home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Database Designers / Rational Rose 2000 / Rational Setup.EXE / common / lib / Win32 / TieRegistry.pm < prev    next >
Text File  |  1998-11-15  |  115KB  |  3,441 lines

  1. # Win32/TieRegistry.pm -- Perl module to easily use a Registry
  2. # (on Win32 systems so far).
  3. # by Tye McQueen, tye@metronet.com, see http://www.metronet.com/~tye/.
  4.  
  5. #
  6. # Skip to "=head" line for user documentation.
  7. #
  8.  
  9. package Win32::TieRegistry;
  10.  
  11. use strict;
  12. use vars qw( $PACK $VERSION @ISA @EXPORT @EXPORT_OK );
  13.  
  14. $PACK= "Win32::TieRegistry";    # Used in error messages.
  15. $VERSION= '0.21';        # Released Sept 17, 1998
  16.  
  17. use Carp;
  18. require Tie::Hash;
  19. @ISA= qw(Tie::Hash);
  20.  
  21. # Required other modules:
  22. use Win32API::Registry 0.12 qw( :KEY_ :HKEY_ :REG_ );
  23.  
  24. #Optional other modules:
  25. use vars qw( $_NoMoreItems $_FileNotFound $_TooSmall $_MoreData $_SetDualVar );
  26.  
  27. if(  eval { require Win32::WinError }  ) {
  28.     $_NoMoreItems= Win32::WinError::constant("ERROR_NO_MORE_ITEMS",0);
  29.     $_FileNotFound= Win32::WinError::constant("ERROR_FILE_NOT_FOUND",0);
  30.     $_TooSmall= Win32::WinError::constant("ERROR_INSUFFICIENT_BUFFER",0);
  31.     $_MoreData= Win32::WinError::constant("ERROR_MORE_DATA",0);
  32. } else {
  33.     $_NoMoreItems= "^No more data";
  34.     $_FileNotFound= "cannot find the file";
  35.     $_TooSmall= " data area passed to ";
  36.     $_MoreData= "^more data is avail";
  37. }
  38. if(  $_SetDualVar= eval { require SetDualVar }  ) {
  39.     import SetDualVar;
  40. }
  41.  
  42.  
  43. #Implementation details:
  44. #    When opened:
  45. #    HANDLE        long; actual handle value
  46. #    MACHINE        string; name of remote machine ("" if local)
  47. #    PATH        list ref; machine-relative full path for this key:
  48. #            ["LMachine","System","Disk"]
  49. #            ["HKEY_LOCAL_MACHINE","System","Disk"]
  50. #    DELIM        char; delimiter used to separate subkeys (def="\\")
  51. #    OS_DELIM    char; always "\\" for Win32
  52. #    ACCESS        long; usually KEY_ALL_ACCESS, perhaps KEY_READ, etc.
  53. #    ROOTS        string; var name for "Lmachine"->HKEY_LOCAL_MACHINE map
  54. #    FLAGS        int; bits to control certain options
  55. #    Often:
  56. #    VALUES        ref to list of value names (data/type never cached)
  57. #    SUBKEYS        ref to list of subkey names
  58. #    SUBCLASSES    ref to list of subkey classes
  59. #    SUBTIMES    ref to list of subkey write times
  60. #    MEMBERS        ref to list of subkey_name.DELIM's, DELIM.value_name's
  61. #    MEMBHASH    hash ref to with MEMBERS as keys and 1's as values
  62. #    Once Key "Info" requested:
  63. #    Class CntSubKeys CntValues MaxSubKeyLen MaxSubClassLen
  64. #    MaxValNameLen MaxValDataLen SecurityLen LastWrite
  65. #    When tied to a hash and iterating over key values:
  66. #    PREVIDX        int; index of last MEMBERS element return
  67. #    When tied to a hash and iterating over key values:
  68. #    UNLOADME    list ref; information about Load()ed key
  69. #    When a subkey of a "loaded" key:
  70. #    DEPENDON    obj ref; object that can't be destroyed before us
  71.  
  72.  
  73. #Package-local variables:
  74.  
  75. # Option flag bits:
  76. use vars qw( $Flag_ArrVal $Flag_TieVal $Flag_DualTyp $Flag_DualBin
  77.          $Flag_FastDel $Flag_HexDWord $Flag_Split $Flag_FixNulls );
  78. $Flag_ArrVal=    0x0001;
  79. $Flag_TieVal=    0x0002;
  80. $Flag_FastDel=    0x0004;
  81. $Flag_HexDWord=    0x0008;
  82. $Flag_Split=    0x0010;
  83. $Flag_DualTyp=    0x0020;
  84. $Flag_DualBin=    0x0040;
  85. $Flag_FixNulls=    0x0080;
  86.  
  87.  
  88. use vars qw( $RegObj %_Roots %RegHash $Registry );
  89.  
  90. # Short-hand for HKEY_* constants:
  91. %_Roots= (
  92.     "Classes" =>    HKEY_CLASSES_ROOT,
  93.     "CUser" =>        HKEY_CURRENT_USER,
  94.     "LMachine" =>    HKEY_LOCAL_MACHINE,
  95.     "Users" =>        HKEY_USERS,
  96.     "PerfData" =>    HKEY_PERFORMANCE_DATA,    # Too picky to be useful
  97.     "CConfig" =>    HKEY_CURRENT_CONFIG,
  98.     "DynData" =>    HKEY_DYN_DATA,        # Too picky to be useful
  99. );
  100.  
  101. # Basic master Registry object:
  102. $RegObj= {};
  103. @$RegObj{qw( HANDLE MACHINE PATH DELIM OS_DELIM ACCESS FLAGS ROOTS )}= (
  104.     "NONE", "", [], "\\", "\\",
  105.     KEY_READ|KEY_WRITE, $Flag_HexDWord|$Flag_FixNulls, "${PACK}::_Roots" );
  106. $RegObj->{FLAGS} |= $Flag_DualTyp|$Flag_DualBin   if  $_SetDualVar;
  107. bless $RegObj;
  108.  
  109. # Fill cache for master Registry object:
  110. @$RegObj{qw( VALUES SUBKEYS SUBCLASSES SUBTIMES )}= (
  111.     [],  [ keys(%_Roots) ],  [],  []  );
  112. grep( s#$#$RegObj->{DELIM}#,
  113.   @{ $RegObj->{MEMBERS}= [ @{$RegObj->{SUBKEYS}} ] } );
  114. @$RegObj{qw( Class MaxSubKeyLen MaxSubClassLen MaxValNameLen
  115.   MaxValDataLen SecurityLen LastWrite CntSubKeys CntValues )}=
  116.     ( "", 0, 0, 0, 0, 0, 0, 0, 0 );
  117.  
  118. # Create master Registry tied hash:
  119. $RegObj->Tie( \%RegHash );
  120.  
  121. # Create master Registry combination object and tied hash reference:
  122. $Registry= \%RegHash;
  123. bless $Registry;
  124.  
  125.  
  126. # Preloaded methods go here.
  127.  
  128. # Map option names to name of subroutine that controls that option:
  129. use vars qw( @_opt_subs %_opt_subs );
  130. @_opt_subs= qw( Delimiter ArrayValues TieValues SplitMultis DWordsToHex
  131.     FastDelete FixSzNulls DualTypes DualBinVals AllowLoad AllowSave );
  132. @_opt_subs{@_opt_subs}= @_opt_subs;
  133.  
  134. sub import
  135. {
  136.   my $pkg= shift(@_);
  137.   my $level= $Exporter::ExportLevel;
  138.   my $expto= caller($level);
  139.   my @export= ();
  140.   my @consts= qw( :KEY_ :REG_ );
  141.   my $registry= $Registry->Clone;
  142.   local( $_ );
  143.     while(  @_  ) {
  144.     $_= shift(@_);
  145.     if(  /^\$(\w+::)*\w+$/  ) {
  146.         push( @export, "ObjVar" )   if  /^\$RegObj$/;
  147.         push( @export, $_ );
  148.     } elsif(  /^\%(\w+::)*\w+$/  ) {
  149.         push( @export, $_ );
  150.     } elsif(  /^[$%]/  ) {
  151.         croak "${PACK}->import:  Invalid variable name ($_)";
  152.     } elsif(  /^:/  ||  /^(H?KEY|REG)_/  ) {
  153.         Win32API::Registry->export( $expto, $_ )
  154.           unless  /^:$/;
  155.         @consts= ();
  156.     } elsif(  ! @_  ) {
  157.         croak "${PACK}->import:  Missing argument after option ($_)";
  158.     } elsif(  exists $_opt_subs{$_}  ) {
  159.         $_= $_opt_subs{$_};
  160.         $registry->$_( shift(@_) );
  161.     } elsif(  /^TiedRef$/  ) {
  162.         $_= shift(@_);
  163.         if(  ! ref($_)  &&  /^(\$?)(\w+::)*\w+$/  ) {
  164.         $_= '$'.$_   unless  '$' eq $1;
  165.         } elsif(  "SCALAR" ne ref($_)  ) {
  166.         croak "${PACK}->import:  Invalid var after TiedRef ($_)";
  167.         }
  168.         push( @export, $_ );
  169.     } elsif(  /^TiedHash$/  ) {
  170.         $_= shift(@_);
  171.         if(  ! ref($_)  &&  /^(\%?)(\w+::)*\w+$/  ) {
  172.         $_= '%'.$_   unless  '%' eq $1;
  173.         } elsif(  "HASH" ne ref($_)  ) {
  174.         croak "${PACK}->import:  Invalid var after TiedHash ($_)";
  175.         }
  176.         push( @export, $_ );
  177.     } elsif(  /^ObjectRef$/  ) {
  178.         $_= shift(@_);
  179.         if(  ! ref($_)  &&  /^(\$?)(\w+::)*\w+$/  ) {
  180.         push( @export, "ObjVar" );
  181.         $_= '$'.$_   unless  '$' eq $1;
  182.         } elsif(  "SCALAR" eq ref($_)  ) {
  183.         push( @export, "ObjRef" );
  184.         } else {
  185.         croak "${PACK}->import:  Invalid var after ObjectRef ($_)";
  186.         }
  187.         push( @export, $_ );
  188.     } elsif(  /^ExportLevel$/  ) {
  189.         $level= shift(@_);
  190.         $expto= caller($level);
  191.     } elsif(  /^ExportTo$/  ) {
  192.         undef $level;
  193.         $expto= caller($level);
  194.     } else {
  195.         croak "${PACK}->import:  Invalid option ($_)";
  196.     }
  197.     }
  198.     @export= ('$Registry')   unless  @export;
  199.     while(  @export  ) {
  200.     $_= shift( @export );
  201.     if(  /^\$((?:\w+::)*)(\w+)$/  ) {
  202.       my( $pack, $sym )= ( $1, $2 );
  203.         $pack= $expto   unless  defined($pack)  &&  "" ne $pack;
  204.         no strict 'refs';
  205.         *{"${pack}::$sym"}= \${"${pack}::$sym"};
  206.         ${"${pack}::$sym"}= $registry;
  207.     } elsif(  /^\%((?:\w+::)*)(\w+)$/  ) {
  208.       my( $pack, $sym )= ( $1, $2 );
  209.         $pack= $expto   unless  defined($pack)  &&  "" ne $pack;
  210.         no strict 'refs';
  211.         *{"${pack}::$sym"}= \%{"${pack}::$sym"};
  212.         $registry->Tie( \%{"${pack}::$sym"} );
  213.     } elsif(  "SCALAR" eq ref($_)  ) {
  214.         $$_= $registry;
  215.     } elsif(  "HASH" eq ref($_)  ) {
  216.         $registry->Tie( $_ );
  217.     } elsif(  /^ObjVar$/  ) {
  218.         $_= shift( @_ );
  219.         /^\$((?:\w+::)*)(\w+)$/;
  220.       my( $pack, $sym )= ( $1, $2 );
  221.         $pack= $expto   unless  defined($pack)  &&  "" ne $pack;
  222.         no strict 'refs';
  223.         *{"${pack}::$sym"}= \${"${pack}::$sym"};
  224.         ${"${pack}::$sym"}= $registry->ObjectRef;
  225.     } elsif(  /^ObjRef$/  ) {
  226.         ${shift(@_)}= $registry->ObjectRef;
  227.     } else {
  228.         die "Impossible var to export ($_)";
  229.     }
  230.     }
  231. }
  232.  
  233. use vars qw( @_new_Opts %_new_Opts );
  234. @_new_Opts= qw( ACCESS DELIM MACHINE DEPENDON );
  235. @_new_Opts{@_new_Opts}= (1) x @_new_Opts;
  236.  
  237. sub _new
  238. {
  239.   my $this= shift( @_ );
  240.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  241.   my $class= ref($this) || $this;
  242.   my $self= {};
  243.   my( $handle, $rpath, $opts )= @_;
  244.     if(  @_ < 2  ||  "ARRAY" ne ref($rpath)  ||  3 < @_
  245.      ||  3 == @_ && "HASH" ne ref($opts)  ) {
  246.     croak "Usage:  ${PACK}->_new( \$handle, \\\@path, {OPT=>VAL,...} );\n",
  247.           "  options: @_new_Opts\nCalled";
  248.     }
  249.     @$self{qw( HANDLE PATH )}= ( $handle, $rpath );
  250.     @$self{qw( MACHINE ACCESS DELIM OS_DELIM ROOTS FLAGS )}=
  251.       ( $this->Machine, $this->Access, $this->Delimiter,
  252.         $this->OS_Delimiter, $this->_Roots, $this->_Flags );
  253.     if(  ref($opts)  ) {
  254.       my @err= grep( ! $_new_Opts{$_}, keys(%$opts) );
  255.     @err  and  croak "${PACK}->_new:  Invalid options (@err)";
  256.     @$self{ keys(%$opts) }= values(%$opts);
  257.     }
  258.     bless $self, $class;
  259.     return $self;
  260. }
  261.  
  262.  
  263. sub _split
  264. {
  265.   my $self= shift( @_ );
  266.     $self= tied(%$self)  if  tied(%$self);
  267.   my $path= shift( @_ );
  268.   my $delim= @_ ? shift(@_) : $self->Delimiter;
  269.   my $list= [ split( /\Q$delim/, $path ) ];
  270.     $list;
  271. }
  272.  
  273.  
  274. sub _rootKey
  275. {
  276.   my $self= shift(@_);
  277.     $self= tied(%$self)  if  tied(%$self);
  278.   my $keyPath= shift(@_);
  279.   my $delim= @_ ? shift(@_) : $self->Delimiter;
  280.   my( $root, $subPath );
  281.     if(  "ARRAY" eq ref($keyPath)  ) {
  282.     $subPath= $keyPath;
  283.     } else {
  284.     $subPath= $self->_split( $keyPath, $delim );
  285.     }
  286.     $root= shift( @$subPath );
  287.     if(  $root =~ /^HKEY_/  ) {
  288.       my $handle= Win32API::Registry::constant($root,0);
  289.     $handle  or  croak "Invalid HKEY_ constant ($root): $!";
  290.     return( $self->_new( $handle, [$root], {DELIM=>$delim} ),
  291.             $subPath );
  292.     } elsif(  $root =~ /^([-+]|0x)?\d/  ) {
  293.     return( $self->_new( $root, [sprintf("0x%lX",$root)],
  294.                  {DELIM=>$delim} ),
  295.         $subPath );
  296.     } else {
  297.       my $roots= $self->Roots;
  298.     if(  $roots->{$root}  ) {
  299.         return( $self->_new( $roots->{$root}, [$root], {DELIM=>$delim} ),
  300.                 $subPath );
  301.     }
  302.     croak "No such root key ($root)";
  303.     }
  304. }
  305.  
  306.  
  307. sub _open
  308. {
  309.   my $this= shift(@_);
  310.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  311.   my $subPath= shift(@_);
  312.   my $sam= @_ ? shift(@_) : $this->Access;
  313.   my $subKey= join( $this->OS_Delimiter, @$subPath );
  314.   my $handle= 0;
  315.     $this->RegOpenKeyEx( $subKey, 0, $sam, $handle )
  316.       or  return wantarray ? () : undef;
  317.     return $this->_new( $handle, [ @{$this->_Path}, @$subPath ],
  318.       { ACCESS=>$sam, ( defined($this->{UNLOADME}) ? ("DEPENDON",$this)
  319.     : defined($this->{DEPENDON}) ? ("DEPENDON",$this->{DEPENDON}) : () )
  320.       } );
  321. }
  322.  
  323.  
  324. sub ObjectRef
  325. {
  326.   my $self= shift(@_);
  327.     $self= tied(%$self)  if  tied(%$self);
  328.     $self;
  329. }
  330.  
  331.  
  332. sub _connect
  333. {
  334.   my $this= shift(@_);
  335.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  336.   my $subPath= pop(@_);
  337.     $subPath= $this->_split( $subPath )   unless  ref($subPath);
  338.   my $machine= @_ ? shift(@_) : shift(@$subPath);
  339.   my $handle= 0;
  340.   my( $temp )= $this->_rootKey( [@$subPath] );
  341.     $temp->RegConnectRegistry( $machine, $temp->Handle, $handle )
  342.       or  return wantarray ? () : undef;
  343.   my $self= $this->_new( $handle, [shift(@$subPath)], {MACHINE=>$machine} );
  344.     ( $self, $subPath );
  345. }
  346.  
  347.  
  348. use vars qw( @Connect_Opts %Connect_Opts );
  349. @Connect_Opts= qw(Access Delimiter);
  350. @Connect_Opts{@Connect_Opts}= (1) x @Connect_Opts;
  351.  
  352. sub Connect
  353. {
  354.   my $this= shift(@_);
  355.   my $tied=  ref($this)  &&  tied(%$this);
  356.     $this= tied(%$this)  if  $tied;
  357.   my( $machine, $key, $opts )= @_;
  358.   my $delim= "";
  359.   my $sam;
  360.   my $subPath;
  361.     if(  @_ < 2  ||  3 < @_
  362.      ||  3 == @_ && "HASH" ne ref($opts)  ) {
  363.     croak "Usage:  \$obj= ${PACK}->Connect(",
  364.           " \$Machine, \$subKey, { OPT=>VAL,... } );\n",
  365.           "  options: @Connect_Opts\nCalled";
  366.     }
  367.     if(  ref($opts)  ) {
  368.       my @err= grep( ! $Connect_Opts{$_}, keys(%$opts) );
  369.     @err  and  croak "${PACK}->Connect:  Invalid options (@err)";
  370.     }
  371.     $delim= "$opts->{Delimiter}"  if  defined($opts->{Delimiter});
  372.     $delim= $this->Delimiter   if  "" eq $delim;
  373.     $sam= defined($opts->{Access}) ? $opts->{Access} : $this->Access;
  374.     $sam= Win32API::Registry::constant($sam,0)   if  $sam =~ /^KEY_/;
  375.     ( $this, $subPath )= $this->_connect( $machine, $key );
  376.     return wantarray ? () : undef   unless  defined($this);
  377.   my $self= $this->_open( $subPath, $sam );
  378.     return wantarray ? () : undef   unless  defined($self);
  379.     $self->Delimiter( $delim );
  380.     $self= $self->TiedRef   if  $tied;
  381.     return $self;
  382. }
  383.  
  384.  
  385. my @_newVirtual_keys= qw( MEMBERS VALUES SUBKEYS SUBTIMES SUBCLASSES
  386.     Class SecurityLen LastWrite CntValues CntSubKeys
  387.     MaxValNameLen MaxValDataLen MaxSubKeyLen MaxSubClassLen );
  388.  
  389. sub _newVirtual
  390. {
  391.   my $self= shift(@_);
  392.   my( $rPath, $root, $opts )= @_;
  393.   my $new= $self->_new( "NONE", $rPath, $opts )
  394.       or  return wantarray ? () : undef;
  395.     @{$new}{@_newVirtual_keys}= @{$root->ObjectRef}{@_newVirtual_keys};
  396.     return $new;
  397. }
  398.  
  399.  
  400. #$key= new Win32::TieRegistry "LMachine/System/Disk";
  401. #$key= new Win32::TieRegistry "//Server1/LMachine/System/Disk";
  402. #Win32::TieRegistry->new( HKEY_LOCAL_MACHINE, {DELIM=>"/",ACCESS=>KEY_READ} );
  403. #Win32::TieRegistry->new( [ HKEY_LOCAL_MACHINE, ".../..." ], {DELIM=>$DELIM} );
  404. #$key->new( ... );
  405.  
  406. use vars qw( @new_Opts %new_Opts );
  407. @new_Opts= qw(Access Delimiter);
  408. @new_Opts{@new_Opts}= (1) x @new_Opts;
  409.  
  410. sub new
  411. {
  412.   my $this= shift( @_ );
  413.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  414.   my( $subKey, $opts )= @_;
  415.   my $delim= "";
  416.   my $dlen;
  417.   my $sam;
  418.   my $subPath;
  419.     if(  @_ < 1  ||  2 < @_
  420.      ||  2 == @_ && "HASH" ne ref($opts)  ) {
  421.     croak "Usage:  \$obj= ${PACK}->new( \$subKey, { OPT=>VAL,... } );\n",
  422.           "  options: @new_Opts\nCalled";
  423.     }
  424.     if(  defined($opts)  ) {
  425.       my @err= grep( ! $new_Opts{$_}, keys(%$opts) );
  426.     @err  and  die "${PACK}->new:  Invalid options (@err)";
  427.     }
  428.     $delim= "$opts->{Delimiter}"  if  defined($opts->{Delimiter});
  429.     $delim= $this->Delimiter   if  "" eq $delim;
  430.     $dlen= length($delim);
  431.     $sam= defined($opts->{Access}) ? $opts->{Access} : $this->Access;
  432.     $sam= Win32API::Registry::constant($sam,0)   if  $sam =~ /^KEY_/;
  433.     if(  "ARRAY" eq ref($subKey)  ) {
  434.     $subPath= $subKey;
  435.     if(  "NONE" eq $this->Handle  &&  @$subPath  ) {
  436.         ( $this, $subPath )= $this->_rootKey( $subPath );
  437.     }
  438.     } elsif(  $delim x 2 eq substr($subKey,0,2*$dlen)  ) {
  439.       my $path= $this->_split( substr($subKey,2*$dlen), $delim );
  440.       my $mach= shift(@$path);
  441.     if(  ! @$path  ) {
  442.         return $this->_newVirtual( $path, $Registry,
  443.                 {MACHINE=>$mach,DELIM=>$delim,ACCESS=>$sam} );
  444.     }
  445.     ( $this, $subPath )= $this->_connect( $mach, $path );
  446.     return wantarray ? () : undef   if  ! defined($this);
  447.     if(  0 == @$subPath  ) {
  448.         $this->Delimiter( $delim );
  449.         return $this;
  450.     }
  451.     } elsif(  $delim eq substr($subKey,0,$dlen)  ) {
  452.     ( $this, $subPath )= $this->_rootKey( substr($subKey,$dlen), $delim );
  453.     } elsif(  "NONE" eq $this->Handle  &&  "" ne $subKey  ) {
  454.       my( $mach )= $this->Machine;
  455.     if(  $mach  ) {
  456.         ( $this, $subPath )= $this->_connect( $mach, $subKey );
  457.     } else {
  458.         ( $this, $subPath )= $this->_rootKey( $subKey, $delim );
  459.     }
  460.     } else {
  461.     $subPath= $this->_split( $subKey, $delim );
  462.     }
  463.     return wantarray ? () : undef   unless  defined($this);
  464.     if(  0 == @$subPath  &&  "NONE" eq $this->Handle  ) {
  465.     return $this->_newVirtual( $this->_Path, $this,
  466.                    { DELIM=>$delim, ACCESS=>$sam } );
  467.     }
  468.   my $self= $this->_open( $subPath, $sam );
  469.     return wantarray ? () : undef   unless  defined($self);
  470.     $self->Delimiter( $delim );
  471.     return $self;
  472. }
  473.  
  474.  
  475. sub Open
  476. {
  477.   my $self= shift(@_);
  478.   my $tied=  ref($self)  &&  tied(%$self);
  479.     $self= tied(%$self)  if  $tied;
  480.     $self= $self->new( @_ );
  481.     $self= $self->TiedRef   if  defined($self)  &&  $tied;
  482.     return $self;
  483. }
  484.  
  485.  
  486. sub Clone
  487. {
  488.   my $self= shift( @_ );
  489.   my $new= $self->Open("");
  490.     return $new;
  491. }
  492.  
  493.  
  494. { my @flush;
  495.  
  496. sub Flush
  497. {
  498.   my $self= shift(@_);
  499.     $self= tied(%$self)  if  tied(%$self);
  500.   my( $flush )= @_;
  501.     @_  and  croak "Usage:  \$key->Flush( \$bFlush );";
  502.     return 0   if  "NONE" eq $self->Handle;
  503.     @flush= qw( VALUES SUBKEYS SUBCLASSES SUBTIMES MEMBERS Class
  504.         CntSubKeys CntValues MaxSubKeyLen MaxSubClassLen
  505.         MaxValNameLen MaxValDataLen SecurityLen LastWrite PREVIDX )
  506.       unless  @flush;
  507.     delete( @$self{@flush} );
  508.     if(  defined($flush)  &&  $flush  ) {
  509.     return $self->RegFlushKey();
  510.     } else {
  511.     return 1;
  512.     }
  513. }
  514. }
  515.  
  516.  
  517. sub _DualVal
  518. {
  519.   my( $hRef, $num )= @_;
  520.     if(  $_SetDualVar  &&  $$hRef{$num}  ) {
  521.     &SetDualVar( $num, "$$hRef{$num}", 0+$num );
  522.     }
  523.     $num;
  524. }
  525.  
  526.  
  527. use vars qw( @_RegDataTypes %_RegDataTypes );
  528. @_RegDataTypes= qw( REG_NONE REG_SZ REG_EXPAND_SZ REG_BINARY
  529.             REG_DWORD_LITTLE_ENDIAN REG_DWORD_BIG_ENDIAN
  530.             REG_DWORD REG_LINK REG_MULTI_SZ REG_RESOURCE_LIST
  531.             REG_FULL_RESOURCE_DESCRIPTOR
  532.             REG_RESOURCE_REQUIREMENTS_LIST );
  533. # Make sure REG_DWORD appears _after_ other REG_DWORD_* items above.
  534. foreach(  @_RegDataTypes  ) {
  535.     $_RegDataTypes{Win32API::Registry::constant($_,0)}= $_;
  536. }
  537.  
  538. sub GetValue
  539. {
  540.   my $self= shift(@_);
  541.     $self= tied(%$self)  if  tied(%$self);
  542.     1 == @_  or  croak "Usage:  (\$data,\$type)= \$key->GetValue('ValName');";
  543.   my( $valName )= @_;
  544.   my( $valType, $valData, $dLen )= (0,"",0);
  545.     return wantarray ? () : undef   if  "NONE" eq $self->Handle;
  546.     $self->RegQueryValueEx( $valName, [], $valType, $valData,
  547.       $dLen= ( defined($self->{MaxValDataLen}) ? $self->{MaxValDataLen} : 0 )
  548.     )  or  return wantarray ? () : undef;
  549.     if(  REG_DWORD == $valType  ) {
  550.       my $val= unpack("L",$valData);
  551.     $valData= sprintf "0x%08.8lX", $val   if  $self->DWordsToHex;
  552.     &SetDualVar( $valData, $valData, $val )   if  $self->DualBinVals
  553.     } elsif(  REG_BINARY == $valType  &&  length($valData) <= 4  ) {
  554.     &SetDualVar( $valData, $valData, hex reverse unpack("h*",$valData) )
  555.       if  $self->DualBinVals;
  556.     } elsif(  ( REG_SZ == $valType || REG_EXPAND_SZ == $valType )
  557.           &&  $self->FixSzNulls  ) {
  558.     substr($valData,-1)= ""   if  "\0" eq substr($valData,-1);
  559.     } elsif(  REG_MULTI_SZ == $valType  &&  $self->SplitMultis  ) {
  560.     ## $valData =~ s/\0\0$//;    # Why does this often fail??
  561.     substr($valData,-2)= ""   if  "\0\0" eq substr($valData,-2);
  562.     $valData= [ split( /\0/, $valData, -1 ) ]
  563.     }
  564.     if(  ! wantarray  ) {
  565.     return $valData;
  566.     } elsif(  ! $self->DualTypes  ) {
  567.     return( $valData, $valType );
  568.     } else {
  569.     return(  $valData,  _DualVal( \%_RegDataTypes, $valType )  );
  570.     }
  571. }
  572.  
  573.  
  574. sub _ErrNum
  575. {
  576.     # return $^E;
  577.     return Win32::GetLastError();
  578. }
  579.  
  580.  
  581. sub _ErrMsg
  582. {
  583.     # return $^E;
  584.     return Win32::FormatMessage( Win32::GetLastError() );
  585. }
  586.  
  587. sub _Err
  588. {
  589.   my $err;
  590.     # return $^E;
  591.     return _ErrMsg   if  ! $_SetDualVar;
  592.     return &SetDualVar( $err, _ErrMsg, _ErrNum );
  593. }
  594.  
  595. sub _NoMoreItems
  596. {
  597.     $_NoMoreItems =~ /^\d/
  598.        ?  _ErrNum == $_NoMoreItems
  599.        :  _ErrMsg =~ /$_NoMoreItems/io;
  600. }
  601.  
  602.  
  603. sub _FileNotFound
  604. {
  605.     $_FileNotFound =~ /^\d/
  606.        ?  _ErrNum == $_FileNotFound
  607.        :  _ErrMsg =~ /$_FileNotFound/io;
  608. }
  609.  
  610.  
  611. sub _TooSmall
  612. {
  613.     $_TooSmall =~ /^\d/
  614.        ?  _ErrNum == $_TooSmall
  615.        :  _ErrMsg =~ /$_TooSmall/io;
  616. }
  617.  
  618.  
  619. sub _MoreData
  620. {
  621.     $_MoreData =~ /^\d/
  622.        ?  _ErrNum == $_MoreData
  623.        :  _ErrMsg =~ /$_MoreData/io;
  624. }
  625.  
  626.  
  627. sub _enumValues
  628. {
  629.   my $self= shift(@_);
  630.     $self= tied(%$self)  if  tied(%$self);
  631.   my( @names )= ();
  632.   my $pos= 0;
  633.   my $name= "";
  634.   my $nlen= 1+$self->Information("MaxValNameLen");
  635.     while(  $self->RegEnumValue($pos++,$name,$nlen,[],[],[],[])  ) {
  636.     push( @names, $name );
  637.     }
  638.     if(  ! _NoMoreItems()  ) {
  639.     return wantarray ? () : undef;
  640.     }
  641.     $self->{VALUES}= \@names;
  642.     1;
  643. }
  644.  
  645.  
  646. sub ValueNames
  647. {
  648.   my $self= shift(@_);
  649.     $self= tied(%$self)  if  tied(%$self);
  650.     @_  and  croak "Usage:  \@names= \$key->ValueNames;";
  651.     $self->_enumValues   unless  $self->{VALUES};
  652.     return @{$self->{VALUES}};
  653. }
  654.  
  655.  
  656. sub _enumSubKeys
  657. {
  658.   my $self= shift(@_);
  659.     $self= tied(%$self)  if  tied(%$self);
  660.   my( @subkeys, @classes, @times )= ();
  661.   my $pos= 0;
  662.   my( $subkey, $class, $time )= ("","","");
  663.   my( $namSiz, $clsSiz )= $self->Information(
  664.                 qw( MaxSubKeyLen MaxSubClassLen ));
  665.     $namSiz++;  $clsSiz++;
  666.     while(  $self->RegEnumKeyEx(
  667.           $pos++, $subkey, $namSiz, [], $class, $clsSiz, $time )  ) {
  668.     push( @subkeys, $subkey );
  669.     push( @classes, $class );
  670.     push( @times, $time );
  671.     }
  672.     if(  ! _NoMoreItems()  ) {
  673.     return wantarray ? () : undef;
  674.     }
  675.     $self->{SUBKEYS}= \@subkeys;
  676.     $self->{SUBCLASSES}= \@classes;
  677.     $self->{SUBTIMES}= \@times;
  678.     1;
  679. }
  680.  
  681.  
  682. sub SubKeyNames
  683. {
  684.   my $self= shift(@_);
  685.     $self= tied(%$self)  if  tied(%$self);
  686.     @_  and  croak "Usage:  \@names= \$key->SubKeyNames;";
  687.     $self->_enumSubKeys   unless  $self->{SUBKEYS};
  688.     return @{$self->{SUBKEYS}};
  689. }
  690.  
  691.  
  692. sub SubKeyClasses
  693. {
  694.   my $self= shift(@_);
  695.     @_  and  croak "Usage:  \@classes= \$key->SubKeyClasses;";
  696.     $self->_enumSubKeys   unless  $self->{SUBCLASSES};
  697.     return @{$self->{SUBCLASSES}};
  698. }
  699.  
  700.  
  701. sub SubKeyTimes
  702. {
  703.   my $self= shift(@_);
  704.     $self= tied(%$self)  if  tied(%$self);
  705.     @_  and  croak "Usage:  \@times= \$key->SubKeyTimes;";
  706.     $self->_enumSubKeys   unless  $self->{SUBTIMES};
  707.     return @{$self->{SUBTIMES}};
  708. }
  709.  
  710.  
  711. sub _MemberNames
  712. {
  713.   my $self= shift(@_);
  714.     $self= tied(%$self)  if  tied(%$self);
  715.     @_  and  croak "Usage:  \$arrayRef= \$key->_MemberNames;";
  716.     if(  ! $self->{MEMBERS}  ) {
  717.     $self->_enumValues   unless  $self->{VALUES};
  718.     $self->_enumSubKeys   unless  $self->{SUBKEYS};
  719.       my( @members )= (  map( $_.$self->{DELIM}, @{$self->{SUBKEYS}} ),
  720.              map( $self->{DELIM}.$_, @{$self->{VALUES}} )  );
  721.     $self->{MEMBERS}= \@members;
  722.     }
  723.     return $self->{MEMBERS};
  724. }
  725.  
  726.  
  727. sub _MembersHash
  728. {
  729.   my $self= shift(@_);
  730.     $self= tied(%$self)  if  tied(%$self);
  731.     @_  and  croak "Usage:  \$hashRef= \$key->_MembersHash;";
  732.     if(  ! $self->{MEMBHASH}  ) {
  733.       my $aRef= $self->_MemberNames;
  734.     $self->{MEMBHASH}= {};
  735.     @{$self->{MEMBHASH}}{@$aRef}= (1) x @$aRef;
  736.     }
  737.     return $self->{MEMBHASH};
  738. }
  739.  
  740.  
  741. sub MemberNames
  742. {
  743.   my $self= shift(@_);
  744.     $self= tied(%$self)  if  tied(%$self);
  745.     @_  and  croak "Usage:  \@members= \$key->MemberNames;";
  746.     return @{$self->_MemberNames};
  747. }
  748.  
  749.  
  750. sub Information
  751. {
  752.   my $self= shift(@_);
  753.     $self= tied(%$self)  if  tied(%$self);
  754.   my( $time, $nkeys, $nvals, $xsec, $xkey, $xcls, $xname, $xdata )=
  755.       ("",0,0,0,0,0,0,0);
  756.   my $clen= 8;
  757.     if(  ! $self->RegQueryInfoKey( [], [], $nkeys, $xkey, $xcls,
  758.                    $nvals, $xname, $xdata, $xsec, $time )  ) {
  759.     return wantarray ? () : undef;
  760.     }
  761.     if(  defined($self->{Class})  ) {
  762.     $clen= length($self->{Class});
  763.     } else {
  764.     $self->{Class}= "";
  765.     }
  766.     while(  ! $self->RegQueryInfoKey( $self->{Class}, $clen,
  767.                       [],[],[],[],[],[],[],[],[])
  768.         &&  _MoreData  ) {
  769.     $clen *= 2;
  770.     }
  771.   my( %info );
  772.     @info{ qw( LastWrite CntSubKeys CntValues SecurityLen
  773.            MaxValDataLen MaxSubKeyLen MaxSubClassLen MaxValNameLen )
  774.     }=       ( $time,    $nkeys,    $nvals,   $xsec,
  775.                $xdata,       $xkey,       $xcls,         $xname );
  776.     if(  @_  ) {
  777.       my( %check );
  778.     @check{keys(%info)}= keys(%info);
  779.       my( @err )= grep( ! $check{$_}, @_ );
  780.     if(  @err  ) {
  781.         croak "${PACK}::Information- Invalid info requested (@err)";
  782.     }
  783.     return @info{@_};
  784.     } else {
  785.     return %info;
  786.     }
  787. }
  788.  
  789.  
  790. sub Delimiter
  791. {
  792.   my $self= shift(@_);
  793.     $self= tied(%$self)  if  tied(%$self);
  794.     $self= $RegObj   unless  ref($self);
  795.   my( $oldDelim )= $self->{DELIM};
  796.     if(  1 == @_  &&  "" ne "$_[0]"  ) {
  797.     delete $self->{MEMBERS};
  798.     delete $self->{MEMBHASH};
  799.     $self->{DELIM}= "$_[0]";
  800.     } elsif(  0 != @_  ) {
  801.     croak "Usage:  \$oldDelim= \$key->Delimiter(\$newDelim);";
  802.     }
  803.     $oldDelim;
  804. }
  805.  
  806.  
  807. sub Handle
  808. {
  809.   my $self= shift(@_);
  810.     $self= tied(%$self)  if  tied(%$self);
  811.     @_  and  croak "Usage:  \$handle= \$key->Handle;";
  812.     $self= $RegObj   unless  ref($self);
  813.     $self->{HANDLE};
  814. }
  815.  
  816.  
  817. sub Path
  818. {
  819.   my $self= shift(@_);
  820.     $self= tied(%$self)  if  tied(%$self);
  821.     @_  and  croak "Usage:  \$path= \$key->Path;";
  822.   my $delim= $self->{DELIM};
  823.     $self= $RegObj   unless  ref($self);
  824.     if(  "" eq $self->{MACHINE}  ) {
  825.     $delim . join( $delim, @{$self->{PATH}} ) . $delim;
  826.     } else {
  827.     $delim x 2
  828.       . join( $delim, $self->{MACHINE}, @{$self->{PATH}} )
  829.       . $delim;
  830.     }
  831. }
  832.  
  833.  
  834. sub _Path
  835. {
  836.   my $self= shift(@_);
  837.     $self= tied(%$self)  if  tied(%$self);
  838.     @_  and  croak "Usage:  \$arrRef= \$key->_Path;";
  839.     $self= $RegObj   unless  ref($self);
  840.     $self->{PATH};
  841. }
  842.  
  843.  
  844. sub Machine
  845. {
  846.   my $self= shift(@_);
  847.     $self= tied(%$self)  if  tied(%$self);
  848.     @_  and  croak "Usage:  \$machine= \$key->Machine;";
  849.     $self= $RegObj   unless  ref($self);
  850.     $self->{MACHINE};
  851. }
  852.  
  853.  
  854. sub Access
  855. {
  856.   my $self= shift(@_);
  857.     $self= tied(%$self)  if  tied(%$self);
  858.     @_  and  croak "Usage:  \$access= \$key->Access;";
  859.     $self= $RegObj   unless  ref($self);
  860.     $self->{ACCESS};
  861. }
  862.  
  863.  
  864. sub OS_Delimiter
  865. {
  866.   my $self= shift(@_);
  867.     @_  and  croak "Usage:  \$backslash= \$key->OS_Delimiter;";
  868.     $self->{OS_DELIM};
  869. }
  870.  
  871.  
  872. sub _Roots
  873. {
  874.   my $self= shift(@_);
  875.     $self= tied(%$self)  if  ref($self)  &&  tied(%$self);
  876.     @_  and  croak "Usage:  \$varName= \$key->_Roots;";
  877.     $self= $RegObj   unless  ref($self);
  878.     $self->{ROOTS};
  879. }
  880.  
  881.  
  882. sub Roots
  883. {
  884.   my $self= shift(@_);
  885.     $self= tied(%$self)  if  ref($self)  &&  tied(%$self);
  886.     @_  and  croak "Usage:  \$hashRef= \$key->Roots;";
  887.     $self= $RegObj   unless  ref($self);
  888.     eval "\\%$self->{ROOTS}";
  889. }
  890.  
  891.  
  892. sub TIEHASH
  893. {
  894.   my( $this )= shift(@_);
  895.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  896.   my( $key )= @_;
  897.     if(  1 == @_  &&  ref($key)  &&  "$key" =~ /=/  ) {
  898.     return $key;    # $key is already an object (blessed reference).
  899.     }
  900.     return $this->new( @_ );
  901. }
  902.  
  903.  
  904. sub Tie
  905. {
  906.   my $self= shift(@_);
  907.     $self= tied(%$self)  if  tied(%$self);
  908.   my( $hRef )= @_;
  909.     if(  1 != @_  ||  ! ref($hRef)  ||  "$hRef" !~ /(^|=)HASH\(/  ) {
  910.     croak "Usage: \$key->Tie(\\\%hash);";
  911.     }
  912.     tie %$hRef, ref($self), $self;
  913. }
  914.  
  915.  
  916. sub TiedRef
  917. {
  918.   my $self= shift(@_);
  919.     $self= tied(%$self)  if  tied(%$self);
  920.   my $hRef= @_ ? shift(@_) : {};
  921.     return wantarray ? () : undef   if  ! defined($self);
  922.     $self->Tie($hRef);
  923.     bless $hRef, ref($self);
  924.     $hRef;
  925. }
  926.  
  927.  
  928. sub _Flags
  929. {
  930.   my $self= shift(@_);
  931.     $self= tied(%$self)  if  tied(%$self);
  932.   my $oldFlags= $self->{FLAGS};
  933.     if(  1 == @_  ) {
  934.     $self->{FLAGS}= shift(@_);
  935.     } elsif(  0 != @_  ) {
  936.     croak "Usage:  \$oldBits= \$key->_Flags(\$newBits);";
  937.     }
  938.     $oldFlags;
  939. }
  940.  
  941.  
  942. sub ArrayValues
  943. {
  944.   my $self= shift(@_);
  945.     $self= tied(%$self)  if  tied(%$self);
  946.   my $oldFlag= $Flag_ArrVal == ( $Flag_ArrVal & $self->{FLAGS} );
  947.     if(  1 == @_  ) {
  948.       my $bool= shift(@_);
  949.     if(  $bool  ) {
  950.         $self->{FLAGS} |= $Flag_ArrVal;
  951.     } else {
  952.         $self->{FLAGS} &= ~( $Flag_ArrVal | $Flag_TieVal );
  953.     }
  954.     } elsif(  0 != @_  ) {
  955.     croak "Usage:  \$oldBool= \$key->ArrayValues(\$newBool);";
  956.     }
  957.     $oldFlag;
  958. }
  959.  
  960.  
  961. sub TieValues
  962. {
  963.   my $self= shift(@_);
  964.     $self= tied(%$self)  if  tied(%$self);
  965.   my $oldFlag= $Flag_TieVal == ( $Flag_TieVal & $self->{FLAGS} );
  966.     if(  1 == @_  ) {
  967.       my $bool= shift(@_);
  968.     if(  $bool  ) {
  969.         croak "${PACK}->TieValues cannot be enabled with this version";
  970.         $self->{FLAGS} |= $Flag_TieVal;
  971.     } else {
  972.         $self->{FLAGS} &= ~$Flag_TieVal;
  973.     }
  974.     } elsif(  0 != @_  ) {
  975.     croak "Usage:  \$oldBool= \$key->TieValues(\$newBool);";
  976.     }
  977.     $oldFlag;
  978. }
  979.  
  980.  
  981. sub FastDelete
  982. {
  983.   my $self= shift(@_);
  984.     $self= tied(%$self)  if  tied(%$self);
  985.   my $oldFlag= $Flag_FastDel == ( $Flag_FastDel & $self->{FLAGS} );
  986.     if(  1 == @_  ) {
  987.       my $bool= shift(@_);
  988.     if(  $bool  ) {
  989.         $self->{FLAGS} |= $Flag_FastDel;
  990.     } else {
  991.         $self->{FLAGS} &= ~$Flag_FastDel;
  992.     }
  993.     } elsif(  0 != @_  ) {
  994.     croak "Usage:  \$oldBool= \$key->FastDelete(\$newBool);";
  995.     }
  996.     $oldFlag;
  997. }
  998.  
  999.  
  1000. sub SplitMultis
  1001. {
  1002.   my $self= shift(@_);
  1003.     $self= tied(%$self)  if  tied(%$self);
  1004.   my $oldFlag= $Flag_Split == ( $Flag_Split & $self->{FLAGS} );
  1005.     if(  1 == @_  ) {
  1006.       my $bool= shift(@_);
  1007.     if(  $bool  ) {
  1008.         $self->{FLAGS} |= $Flag_Split;
  1009.     } else {
  1010.         $self->{FLAGS} &= ~$Flag_Split;
  1011.     }
  1012.     } elsif(  0 != @_  ) {
  1013.     croak "Usage:  \$oldBool= \$key->SplitMultis(\$newBool);";
  1014.     }
  1015.     $oldFlag;
  1016. }
  1017.  
  1018.  
  1019. sub DWordsToHex
  1020. {
  1021.   my $self= shift(@_);
  1022.     $self= tied(%$self)  if  tied(%$self);
  1023.   my $oldFlag= $Flag_HexDWord == ( $Flag_HexDWord & $self->{FLAGS} );
  1024.     if(  1 == @_  ) {
  1025.       my $bool= shift(@_);
  1026.     if(  $bool  ) {
  1027.         $self->{FLAGS} |= $Flag_HexDWord;
  1028.     } else {
  1029.         $self->{FLAGS} &= ~$Flag_HexDWord;
  1030.     }
  1031.     } elsif(  0 != @_  ) {
  1032.     croak "Usage:  \$oldBool= \$key->DWordsToHex(\$newBool);";
  1033.     }
  1034.     $oldFlag;
  1035. }
  1036.  
  1037.  
  1038. sub FixSzNulls
  1039. {
  1040.   my $self= shift(@_);
  1041.     $self= tied(%$self)  if  tied(%$self);
  1042.   my $oldFlag= $Flag_FixNulls == ( $Flag_FixNulls & $self->{FLAGS} );
  1043.     if(  1 == @_  ) {
  1044.       my $bool= shift(@_);
  1045.     if(  $bool  ) {
  1046.         $self->{FLAGS} |= $Flag_FixNulls;
  1047.     } else {
  1048.         $self->{FLAGS} &= ~$Flag_FixNulls;
  1049.     }
  1050.     } elsif(  0 != @_  ) {
  1051.     croak "Usage:  \$oldBool= \$key->FixSzNulls(\$newBool);";
  1052.     }
  1053.     $oldFlag;
  1054. }
  1055.  
  1056.  
  1057. sub DualTypes
  1058. {
  1059.   my $self= shift(@_);
  1060.     $self= tied(%$self)  if  tied(%$self);
  1061.   my $oldFlag= $Flag_DualTyp == ( $Flag_DualTyp & $self->{FLAGS} );
  1062.     if(  1 == @_  ) {
  1063.       my $bool= shift(@_);
  1064.     if(  $bool  ) {
  1065.         croak "${PACK}->DualTypes cannot be enabled since ",
  1066.           "SetDualVar module not installed"
  1067.           unless  $_SetDualVar;
  1068.         $self->{FLAGS} |= $Flag_DualTyp;
  1069.     } else {
  1070.         $self->{FLAGS} &= ~$Flag_DualTyp;
  1071.     }
  1072.     } elsif(  0 != @_  ) {
  1073.     croak "Usage:  \$oldBool= \$key->DualTypes(\$newBool);";
  1074.     }
  1075.     $oldFlag;
  1076. }
  1077.  
  1078.  
  1079. sub DualBinVals
  1080. {
  1081.   my $self= shift(@_);
  1082.     $self= tied(%$self)  if  tied(%$self);
  1083.   my $oldFlag= $Flag_DualBin == ( $Flag_DualBin & $self->{FLAGS} );
  1084.     if(  1 == @_  ) {
  1085.       my $bool= shift(@_);
  1086.     if(  $bool  ) {
  1087.         croak "${PACK}->DualBinVals cannot be enabled since ",
  1088.           "SetDualVar module not installed"
  1089.           unless  $_SetDualVar;
  1090.         $self->{FLAGS} |= $Flag_DualBin;
  1091.     } else {
  1092.         $self->{FLAGS} &= ~$Flag_DualBin;
  1093.     }
  1094.     } elsif(  0 != @_  ) {
  1095.     croak "Usage:  \$oldBool= \$key->DualBinVals(\$newBool);";
  1096.     }
  1097.     $oldFlag;
  1098. }
  1099.  
  1100.  
  1101. sub GetOptions
  1102. {
  1103.   my $self= shift(@_);
  1104.     $self= tied(%$self)  if  tied(%$self);
  1105.   my( $opt, $meth, @old );
  1106.     foreach $opt (  @_  ) {
  1107.     $meth= $_opt_subs{$opt};
  1108.     if(  defined $meth  ) {
  1109.         if(  $opt eq "AllowLoad"  ||  $opt eq "AllowSave"  ) {
  1110.         croak "${PACK}->GetOptions:  Getting current setting of $opt ",
  1111.               "not supported in this release";
  1112.         }
  1113.         push(  @old,  $self->$meth()  );
  1114.     } else {
  1115.         croak "${PACK}->GetOptions:  Invalid option ($opt) ",
  1116.           "not one of ( ", join(" ",grep !/^Allow/, @_opt_subs), " )";
  1117.     }
  1118.     }
  1119.     return wantarray ? @old : $old[-1];
  1120. }
  1121.  
  1122.  
  1123. sub SetOptions
  1124. {
  1125.   my $self= shift(@_);
  1126.     # Don't get object if hash ref so "ref" returns original ref.
  1127.   my( $opt, $meth, @old );
  1128.     while(  @_  ) {
  1129.     $opt= shift(@_);
  1130.     $meth= $_opt_subs{$opt};
  1131.     if(  ! @_  ) {
  1132.         croak "${PACK}->SetOptions:  Option value missing ",
  1133.           "after option name ($opt)";
  1134.     } elsif(  defined $meth  ) {
  1135.         push(  @old,  $self->$meth( shift(@_) )  );
  1136.     } elsif(  $opt eq substr("reference",0,length($opt))  ) {
  1137.         shift(@_)   if  @_;
  1138.         push(  @old,  $self  );
  1139.     } else {
  1140.         croak "${PACK}->SetOptions:  Invalid option ($opt) ",
  1141.           "not one of ( @_opt_subs )";
  1142.     }
  1143.     }
  1144.     return wantarray ? @old : $old[-1];
  1145. }
  1146.  
  1147.  
  1148. sub _parseTiedEnt
  1149. {
  1150.   my $self= shift(@_);
  1151.     $self= tied(%$self)  if  tied(%$self);
  1152.   my $ent= shift(@_);
  1153.   my $delim= shift(@_);
  1154.   my $dlen= length( $delim );
  1155.   my $parent= @_ ? shift(@_) : 0;
  1156.   my $off;
  1157.     if(  $delim x 2 eq substr($ent,0,2*$dlen)  &&  "NONE" eq $self->Handle  ) {
  1158.     if(  0 <= ( $off= index( $ent, $delim x 2, 2*$dlen ) )  ) {
  1159.         (  substr( $ent, 0, $off ),  substr( $ent, 2*$dlen+$off )  );
  1160.     } elsif(  $delim eq substr($ent,-$dlen)  ) {
  1161.         ( substr($ent,0,-$dlen) );
  1162.     } elsif(  2*$dlen <= ( $off= rindex( $ent, $delim ) )  ) {
  1163.         (  substr( $ent, 0, $off ),  undef,  substr( $ent, $dlen+$off )  );
  1164.     } elsif(  $parent  ) {
  1165.         ();
  1166.     } else {
  1167.         ( $ent );
  1168.     }
  1169.     } elsif(  $delim eq substr($ent,0,$dlen)  &&  "NONE" ne $self->Handle  ) {
  1170.     ( undef, substr($ent,$dlen) );
  1171.     } elsif(  $self->{MEMBERS}  &&  $self->_MembersHash->{$ent}  ) {
  1172.     ( substr($ent,0,-$dlen) );
  1173.     } elsif(  0 <= ( $off= index( $ent, $delim x 2 ) )  ) {
  1174.     (  substr( $ent, 0, $off ),  substr( $ent, 2*$dlen+$off ) );
  1175.     } elsif(  $delim eq substr($ent,-$dlen)  ) {
  1176.     if(  $parent
  1177.      &&  0 <= ( $off= rindex( $ent, $delim, length($ent)-2*$dlen ) )  ) {
  1178.         (  substr($ent,0,$off),  undef,  undef,
  1179.            substr($ent,$dlen+$off,-$dlen)  );
  1180.     } else {
  1181.         ( substr($ent,0,-$dlen) );
  1182.     }
  1183.     } elsif(  0 <= ( $off= rindex( $ent, $delim ) )  ) {
  1184.     (  substr( $ent, 0, $off ),  undef,  substr( $ent, $dlen+$off )  );
  1185.     } else {
  1186.     ( undef, undef, $ent );
  1187.     }
  1188. }
  1189.  
  1190.  
  1191. sub FETCH
  1192. {
  1193.   my $self= shift(@_);
  1194.   my $ent= shift(@_);
  1195.   my $delim= $self->Delimiter;
  1196.   my( $key, $val, $ambig )= $self->_parseTiedEnt( $ent, $delim, 0 );
  1197.   my $sub;
  1198.     if(  defined($key)  ) {
  1199.     if(  defined($self->{MEMBHASH})
  1200.      &&  $self->{MEMBHASH}->{$key.$delim}
  1201.      &&  0 <= index($key,$delim)  ) {
  1202.         return wantarray ? () : undef
  1203.           unless  $sub= $self->new( $key,
  1204.                   {"Delimiter"=>$self->OS_Delimiter} );
  1205.         $sub->Delimiter($delim);
  1206.     } else {
  1207.         return wantarray ? () : undef
  1208.           unless  $sub= $self->new( $key );
  1209.     }
  1210.     } else {
  1211.     $sub= $self;
  1212.     }
  1213.     if(  defined($val)  ) {
  1214.     return $self->ArrayValues ? [ $sub->GetValue( $val ) ]
  1215.                   : $sub->GetValue( $val );
  1216.     } elsif(  ! defined($ambig)  ) {
  1217.     return $sub->TiedRef;
  1218.     } elsif(  defined($key)  ) {
  1219.     return $sub->FETCH(  $ambig  );
  1220.     } elsif(  "" eq $ambig  ) {
  1221.     return $self->ArrayValues ? [ $sub->GetValue( $ambig ) ]
  1222.                   : $sub->GetValue( $ambig );
  1223.     } else {
  1224.       my $data= [ $sub->GetValue( $ambig ) ];
  1225.     return $sub->ArrayValues ? $data : $$data[0]
  1226.       if  0 != @$data;
  1227.     $data= $sub->new( $ambig );
  1228.     return defined($data) ? $data->TiedRef : wantarray ? () : undef;
  1229.     }
  1230. }
  1231.  
  1232.  
  1233. sub _FetchOld
  1234. {
  1235.   my( $self, $key )= @_;
  1236.   my $old= $self->FETCH($key);
  1237.     if(  $old  ) {
  1238.       my $copy= {};
  1239.     %$copy= %$old;
  1240.     return $copy;
  1241.     }
  1242.     # return $^E;
  1243.     return _Err;
  1244. }
  1245.  
  1246.  
  1247. sub DELETE
  1248. {
  1249.   my $self= shift(@_);
  1250.   my $ent= shift(@_);
  1251.   my $delim= $self->Delimiter;
  1252.   my( $key, $val, $ambig, $subkey )= $self->_parseTiedEnt( $ent, $delim, 1 );
  1253.   my $sub;
  1254.   my $fast= defined(wantarray) ? $self->FastDelete : 2;
  1255.   my $old= 1;    # Value returned if FastDelete is set.
  1256.     if(  defined($key)
  1257.      &&  ( defined($val) || defined($ambig) || defined($subkey) )  ) {
  1258.     return wantarray ? () : undef
  1259.       unless  $sub= $self->new( $key );
  1260.     } else {
  1261.     $sub= $self;
  1262.     }
  1263.     if(  defined($val)  ) {
  1264.     $old= $sub->GetValue($val) || _Err   unless  2 <= $fast;
  1265.     $sub->RegDeleteValue( $val );
  1266.     } elsif(  defined($subkey)  ) {
  1267.     $old= $sub->_FetchOld( $subkey.$delim )   unless  $fast;
  1268.     $sub->RegDeleteKey( $subkey );
  1269.     } elsif(  defined($ambig)  ) {
  1270.     if(  defined($key)  ) {
  1271.         $old= $sub->DELETE($ambig);
  1272.     } else {
  1273.         $old= $sub->GetValue($ambig) || _Err   unless  2 <= $fast;
  1274.         if(  defined( $old )  ) {
  1275.         $sub->RegDeleteValue( $ambig );
  1276.         } else {
  1277.         $old= $sub->_FetchOld( $ambig.$delim )   unless  $fast;
  1278.         $sub->RegDeleteKey( $ambig );
  1279.         }
  1280.     }
  1281.     } elsif(  defined($key)  ) {
  1282.     $old= $sub->_FetchOld( $key.$delim )   unless  $fast;
  1283.     $sub->RegDeleteKey( $key );
  1284.     } else {
  1285.     croak "${PACK}->DELETE:  Key ($ent) can never be deleted";
  1286.     }
  1287.     $old;
  1288. }
  1289.  
  1290.  
  1291. sub SetValue
  1292. {
  1293.   my $self= shift(@_);
  1294.     $self= tied(%$self)  if  tied(%$self);
  1295.   my $name= shift(@_);
  1296.   my $data= shift(@_);
  1297.   my( $type )= @_;
  1298.   my $size;
  1299.     if(  ! defined($type)  ) {
  1300.     if(  "ARRAY" eq ref($data)  ) {
  1301.         croak "${PACK}->SetValue:  Value is array reference but ",
  1302.           "no data type given"
  1303.           unless  2 == @$data;
  1304.         ( $data, $type )= @$data;
  1305.     } else {
  1306.         $type= REG_SZ;
  1307.     }
  1308.     }
  1309.     $type= Win32API::Registry::constant($type,0)   if  $type =~ /^REG_/;
  1310.     if(  REG_MULTI_SZ == $type  &&  "ARRAY" eq ref($data)  ) {
  1311.     $data= join( "\0", @$data ) . "\0\0";
  1312.     ## $data= pack(  "a*" x (1+@$data),  map( $_."\0", @$data, "" )  );
  1313.     } elsif(  ( REG_SZ == $type || REG_EXPAND_SZ == $type )
  1314.           &&  $self->FixSzNulls  ) {
  1315.     $data .= "\0"    unless  "\0" eq substr($data,0,-1);
  1316.     } elsif(  REG_DWORD == $type  &&  $data =~ /^0x[0-9a-fA-F]{3,}$/  ) {
  1317.     $data= pack( "L", hex($data) );
  1318.     # We could to $data=pack("L",$data) for REG_DWORD but I see
  1319.     # no nice way to always destinguish when to do this or not.
  1320.     }
  1321.     $self->RegSetValueEx( $name, 0, $type, $data, length($data) );
  1322. }
  1323.  
  1324.  
  1325. sub StoreKey
  1326. {
  1327.   my $this= shift(@_);
  1328.     $this= tied(%$this)  if  ref($this)  &&  tied(%$this);
  1329.   my $subKey= shift(@_);
  1330.   my $data= shift(@_);
  1331.   my $ent;
  1332.   my $self;
  1333.     if(  ! ref($data)  ||  "$data" !~ /(^|=)HASH/  ) {
  1334.     croak "${PACK}->StoreKey:  For ", $this->Path.$subKey, ",\n",
  1335.           "  subkey data must be a HASH reference";
  1336.     }
  1337.     if(  defined( $$data{""} )  &&  "HASH" eq ref($$data{""})  ) {
  1338.     $self= $this->CreateKey( $subKey, delete $$data{""} );
  1339.     } else {
  1340.     $self= $this->CreateKey( $subKey );
  1341.     }
  1342.     return wantarray ? () : undef   if  ! defined($self);
  1343.     foreach $ent (  keys(%$data)  ) {
  1344.     return wantarray ? () : undef
  1345.       unless  $self->STORE( $ent, $$data{$ent} );
  1346.     }
  1347.     $self;
  1348. }
  1349.  
  1350.  
  1351. # = { "" => {OPT=>VAL}, "val"=>[], "key"=>{} } creates a new key
  1352. # = "string" creates a new REG_SZ value
  1353. # = [ data, type ] creates a new value
  1354. sub STORE
  1355. {
  1356.   my $self= shift(@_);
  1357.   my $ent= shift(@_);
  1358.   my $data= shift(@_);
  1359.   my $delim= $self->Delimiter;
  1360.   my( $key, $val, $ambig, $subkey )= $self->_parseTiedEnt( $ent, $delim, 1 );
  1361.   my $sub;
  1362.     if(  defined($key)
  1363.      &&  ( defined($val) || defined($ambig) || defined($subkey) )  ) {
  1364.     return wantarray ? () : undef
  1365.       unless  $sub= $self->new( $key );
  1366.     } else {
  1367.     $sub= $self;
  1368.     }
  1369.     if(  defined($val)  ) {
  1370.     croak "${PACK}->STORE:  For ", $sub->Path.$delim.$val, ",\n",
  1371.           "  value data cannot be a HASH reference"
  1372.       if  ref($data)  &&  "$data" =~ /(^|=)HASH/;
  1373.     $sub->SetValue( $val, $data );
  1374.     } elsif(  defined($subkey)  ) {
  1375.     croak "${PACK}->STORE:  For ", $sub->Path.$subkey.$delim, ",\n",
  1376.           "  subkey data must be a HASH reference"
  1377.       unless  ref($data)  &&  "$data" =~ /(^|=)HASH/;
  1378.     $sub->StoreKey( $subkey, $data );
  1379.     } elsif(  defined($ambig)  ) {
  1380.     if(  ref($data)  &&  "$data" =~ /(^|=)HASH/  ) {
  1381.         $sub->StoreKey( $ambig, $data );
  1382.     } else {
  1383.         $sub->SetValue( $ambig, $data );
  1384.     }
  1385.     } elsif(  defined($key)  ) {
  1386.     croak "${PACK}->STORE:  For ", $sub->Path.$key.$delim, ",\n",
  1387.           "  subkey data must be a HASH reference"
  1388.       unless  ref($data)  &&  "$data" =~ /(^|=)HASH/;
  1389.     $sub->StoreKey( $key, $data );
  1390.     } else {
  1391.     croak "${PACK}->STORE:  Key ($ent) can never be created nor set";
  1392.     }
  1393. }
  1394.  
  1395.  
  1396. sub EXISTS
  1397. {
  1398.   my $self= shift(@_);
  1399.   my $ent= shift(@_);
  1400.     defined( $self->FETCH($ent) );
  1401. }
  1402.  
  1403.  
  1404. sub FIRSTKEY
  1405. {
  1406.   my $self= shift(@_);
  1407.   my $members= $self->_MemberNames;
  1408.     $self->{PREVIDX}= 0;
  1409.     @{$members} ? $members->[0] : undef;
  1410. }
  1411.  
  1412.  
  1413. sub NEXTKEY
  1414. {
  1415.   my $self= shift(@_);
  1416.   my $prev= shift(@_);
  1417.   my $idx= $self->{PREVIDX};
  1418.   my $members= $self->_MemberNames;
  1419.     if(  ! defined($idx)  ||  $prev ne $members->[$idx]  ) {
  1420.     $idx= 0;
  1421.     while(  $idx < @$members  &&  $prev ne $members->[$idx]  ) {
  1422.         $idx++;
  1423.     }
  1424.     }
  1425.     $self->{PREVIDX}= ++$idx;
  1426.     $members->[$idx];
  1427. }
  1428.  
  1429.  
  1430. sub DESTROY
  1431. {
  1432.   my $self= shift(@_);
  1433.     return   if  tied(%$self);
  1434.   my $unload= $self->{UNLOADME};
  1435.   my $debug= $ENV{DEBUG_TIE_REGISTRY};
  1436.     if(  defined($debug)  ) {
  1437.     if(  1 < $debug  ) {
  1438.       my $hand= $self->Handle;
  1439.       my $dep= $self->{DEPENDON};
  1440.         carp "${PACK} destroying ", $self->Path, " (",
  1441.          "NONE" eq $hand ? $hand : sprintf("0x%lX",$hand), ")",
  1442.          defined($dep) ? (" [depends on ",$dep->Path,"]") : ();
  1443.     } else {
  1444.         warn "${PACK} destroying ", $self->Path, ".\n";
  1445.     }
  1446.     }
  1447.     $self->RegCloseKey
  1448.       unless  "NONE" eq $self->Handle;
  1449.     if(  defined($unload)  ) {
  1450.     if(  defined($debug)  &&  1 < $debug  ) {
  1451.       my( $obj, $subKey, $file )= @$unload;
  1452.         warn "Unloading ", $self->Path,
  1453.           " (from ", $obj->Path, ", $subKey)...\n";
  1454.     }
  1455.     $self->UnLoad
  1456.       ||  warn "Couldn't unload ", $self->Path, ": ", _ErrMsg, "\n";
  1457.     ## carp "Never unloaded ${PACK}::Load($$unload[2])";
  1458.     }
  1459.     #delete $self->{DEPENDON};
  1460. }
  1461.  
  1462.  
  1463. use vars qw( @CreateKey_Opts %CreateKey_Opts );
  1464. @CreateKey_Opts= qw( Access Class Options Delimiter
  1465.              Disposition Security Volatile Backup );
  1466. @CreateKey_Opts{@CreateKey_Opts}= (1) x @CreateKey_Opts;
  1467.  
  1468. sub CreateKey
  1469. {
  1470.   my $self= shift(@_);
  1471.   my $tied= tied(%$self);
  1472.     $self= tied(%$self)  if  $tied;
  1473.   my( $subKey, $opts )= @_;
  1474.   my( $sam )= $self->Access;
  1475.   my( $delim )= $self->Delimiter;
  1476.   my( $class )= "";
  1477.   my( $flags )= 0;
  1478.   my( $secure )= [];
  1479.   my( $garb )= 0;
  1480.   my( $result )= \$garb;
  1481.   my( $handle )= 0;
  1482.     if(  @_ < 1  ||  2 < @_
  1483.      ||  2 == @_ && "HASH" ne ref($opts)  ) {
  1484.     croak "Usage:  \$new= \$old->CreateKey( \$subKey, {OPT=>VAL,...} );\n",
  1485.           "  options: @CreateKey_Opts\nCalled";
  1486.     }
  1487.     if(  defined($opts)  ) {
  1488.     $sam= $opts->{"Access"}   if  defined($opts->{"Access"});
  1489.     $class= $opts->{Class}   if  defined($opts->{Class});
  1490.     $flags= $opts->{Options}   if  defined($opts->{Options});
  1491.     $delim= $opts->{"Delimiter"}   if  defined($opts->{"Delimiter"});
  1492.     $secure= $opts->{Security}   if  defined($opts->{Security});
  1493.     if(  defined($opts->{Disposition})  ) {
  1494.         "SCALAR" eq ref($opts->{Disposition})
  1495.           or  croak "${PACK}->CreateKey option `Disposition'",
  1496.             " must provide a scalar reference";
  1497.         $result= $opts->{Disposition};
  1498.     }
  1499.     $result= ${$opts->{Disposition}}   if  defined($opts->{Disposition});
  1500.     if(  0 == $flags  ) {
  1501.         $flags |= REG_OPTION_VOLATILE
  1502.           if  defined($opts->{Volatile})  &&  $opts->{Volatile};
  1503.         $flags |= REG_OPTION_BACKUP_RESTORE
  1504.           if  defined($opts->{Backup})  &&  $opts->{Backup};
  1505.     }
  1506.     }
  1507.   my $subPath= ref($subKey) ? $subKey : $self->_split($subKey,$delim);
  1508.     $subKey= join( $self->OS_Delimiter, @$subPath );
  1509.     $self->RegCreateKeyEx( $subKey, 0, $class, $flags, $sam,
  1510.                $secure, $handle, $$result )
  1511.       or  return wantarray ? () : undef;
  1512.   my $new= $self->_new( $handle, [ @{$self->_Path}, @{$subPath} ] );
  1513.     $new->{ACCESS}= $sam;
  1514.     $new->{DELIM}= $delim;
  1515.     $new= $new->TiedRef   if  $tied;
  1516.     return $new;
  1517. }
  1518.  
  1519.  
  1520. use vars qw( $Load_Cnt @Load_Opts %Load_Opts );
  1521. $Load_Cnt= 0;
  1522. @Load_Opts= qw(NewSubKey);
  1523. @Load_Opts{@Load_Opts}= (1) x @Load_Opts;
  1524.  
  1525. sub Load
  1526. {
  1527.   my $this= shift(@_);
  1528.   my $tied=  ref($this)  &&  tied(%$this);
  1529.     $this= tied(%$this)  if  $tied;
  1530.   my( $file, $subKey, $opts )= @_;
  1531.     if(  2 == @_  &&  "HASH" eq ref($subKey)  ) {
  1532.     $opts= $subKey;
  1533.     undef $subKey;
  1534.     }
  1535.     @_ < 1  ||  3 < @_  ||  defined($opts) && "HASH" ne ref($opts)
  1536.       and  croak "Usage:  \$key= ",
  1537.          "${PACK}->Load( \$fileName, [\$newSubKey,] {OPT=>VAL...} );\n",
  1538.          "  options: @Load_Opts @new_Opts\nCalled";
  1539.     if(  defined($opts)  &&  exists($opts->{NewSubKey})  ) {
  1540.     $subKey= delete $opts->{NewSubKey};
  1541.     }
  1542.     if(  ! defined( $subKey )  ) {
  1543.     if(  "" ne $this->Machine  ) {
  1544.         ( $this )= $this->_connect( [$this->Machine,"LMachine"] );
  1545.     } else {
  1546.         ( $this )= $this->_rootKey( "LMachine" );    # Could also be "Users"
  1547.     }
  1548.     $subKey= "PerlTie:$$." . ++$Load_Cnt;
  1549.     }
  1550.     $this->RegLoadKey( $subKey, $file )
  1551.       or  return wantarray ? () : undef;
  1552.   my $self= $this->new( $subKey, defined($opts) ? $opts : () );
  1553.     if(  ! defined( $self )  ) {
  1554.     { my $err= Win32::GetLastError();
  1555.     #{ local( $^E );
  1556.         $this->RegUnLoadKey( $subKey )
  1557.           or  carp "Can't unload $subKey from ", $this->Path, ": $^E\n";
  1558.         Win32::SetLastError($err);
  1559.     }
  1560.     return wantarray ? () : undef;
  1561.     }
  1562.     $self->{UNLOADME}= [ $this, $subKey, $file ];
  1563.     $self= $self->TiedRef   if  $tied;
  1564.     $self;
  1565. }
  1566.  
  1567.  
  1568. sub UnLoad
  1569. {
  1570.   my $self= shift(@_);
  1571.     $self= tied(%$self)  if  tied(%$self);
  1572.     @_  and  croak "Usage:  \$key->UnLoad;";
  1573.   my $unload= $self->{UNLOADME};
  1574.     "ARRAY" eq ref($unload)
  1575.       or  croak "${PACK}->UnLoad called on a key which was not Load()ed";
  1576.   my( $obj, $subKey, $file )= @$unload;
  1577.     $self->RegCloseKey;
  1578.     Win32API::Registry::RegUnLoadKey( $obj->Handle, $subKey );
  1579. }
  1580.  
  1581.  
  1582. sub AllowSave
  1583. {
  1584.   my $self= shift(@_);
  1585.     $self= tied(%$self)  if  tied(%$self);
  1586.     $self->AllowPriv( "SeBackupPrivilege", @_ );
  1587. }
  1588.  
  1589.  
  1590. sub AllowLoad
  1591. {
  1592.   my $self= shift(@_);
  1593.     $self= tied(%$self)  if  tied(%$self);
  1594.     $self->AllowPriv( "SeRestorePrivilege", @_ );
  1595. }
  1596.  
  1597.  
  1598. # RegNotifyChangeKeyValue( hKey, bWatchSubtree, iNotifyFilter, hEvent, bAsync )
  1599.  
  1600.  
  1601. sub RegCloseKey { my $self= shift(@_);
  1602.     Win32API::Registry::RegCloseKey $self->Handle, @_; }
  1603. sub RegConnectRegistry { my $self= shift(@_);
  1604.     Win32API::Registry::RegConnectRegistry @_; }
  1605. sub RegCreateKey { my $self= shift(@_);
  1606.     Win32API::Registry::RegCreateKey $self->Handle, @_; }
  1607. sub RegCreateKeyEx { my $self= shift(@_);
  1608.     Win32API::Registry::RegCreateKeyEx $self->Handle, @_; }
  1609. sub RegDeleteKey { my $self= shift(@_);
  1610.     Win32API::Registry::RegDeleteKey $self->Handle, @_; }
  1611. sub RegDeleteValue { my $self= shift(@_);
  1612.     Win32API::Registry::RegDeleteValue $self->Handle, @_; }
  1613. sub RegEnumKey { my $self= shift(@_);
  1614.     Win32API::Registry::RegEnumKey $self->Handle, @_; }
  1615. sub RegEnumKeyEx { my $self= shift(@_);
  1616.     Win32API::Registry::RegEnumKeyEx $self->Handle, @_; }
  1617. sub RegEnumValue { my $self= shift(@_);
  1618.     Win32API::Registry::RegEnumValue $self->Handle, @_; }
  1619. sub RegFlushKey { my $self= shift(@_);
  1620.     Win32API::Registry::RegFlushKey $self->Handle, @_; }
  1621. sub RegGetKeySecurity { my $self= shift(@_);
  1622.     Win32API::Registry::RegGetKeySecurity $self->Handle, @_; }
  1623. sub RegLoadKey { my $self= shift(@_);
  1624.     Win32API::Registry::RegLoadKey $self->Handle, @_; }
  1625. sub RegNotifyChangeKeyValue { my $self= shift(@_);
  1626.     Win32API::Registry::RegNotifyChangeKeyValue $self->Handle, @_; }
  1627. sub RegOpenKey { my $self= shift(@_);
  1628.     Win32API::Registry::RegOpenKey $self->Handle, @_; }
  1629. sub RegOpenKeyEx { my $self= shift(@_);
  1630.     Win32API::Registry::RegOpenKeyEx $self->Handle, @_; }
  1631. sub RegQueryInfoKey { my $self= shift(@_);
  1632.     Win32API::Registry::RegQueryInfoKey $self->Handle, @_; }
  1633. sub RegQueryMultipleValues { my $self= shift(@_);
  1634.     Win32API::Registry::RegQueryMultipleValues $self->Handle, @_; }
  1635. sub RegQueryValue { my $self= shift(@_);
  1636.     Win32API::Registry::RegQueryValue $self->Handle, @_; }
  1637. sub RegQueryValueEx { my $self= shift(@_);
  1638.     Win32API::Registry::RegQueryValueEx $self->Handle, @_; }
  1639. sub RegReplaceKey { my $self= shift(@_);
  1640.     Win32API::Registry::RegReplaceKey $self->Handle, @_; }
  1641. sub RegRestoreKey { my $self= shift(@_);
  1642.     Win32API::Registry::RegRestoreKey $self->Handle, @_; }
  1643. sub RegSaveKey { my $self= shift(@_);
  1644.     Win32API::Registry::RegSaveKey $self->Handle, @_; }
  1645. sub RegSetKeySecurity { my $self= shift(@_);
  1646.     Win32API::Registry::RegSetKeySecurity $self->Handle, @_; }
  1647. sub RegSetValue { my $self= shift(@_);
  1648.     Win32API::Registry::RegSetValue $self->Handle, @_; }
  1649. sub RegSetValueEx { my $self= shift(@_);
  1650.     Win32API::Registry::RegSetValueEx $self->Handle, @_; }
  1651. sub RegUnLoadKey { my $self= shift(@_);
  1652.     Win32API::Registry::RegUnLoadKey $self->Handle, @_; }
  1653. sub AllowPriv { my $self= shift(@_);
  1654.     Win32API::Registry::AllowPriv @_; }
  1655.  
  1656.  
  1657. # Autoload methods go after =cut, and are processed by the autosplit program.
  1658.  
  1659. 1;
  1660. __END__
  1661.  
  1662. =head1 NAME
  1663.  
  1664. Win32::TieRegistry - Powerful and easy ways to manipulate a registry
  1665. [on Win32 for now].
  1666.  
  1667. =head1 SYNOPSIS
  1668.  
  1669.   use Win32::TieRegistry 0.20 ( UseOptionName=>UseOptionValue[,...] );
  1670.  
  1671.   $Registry->SomeMethodCall(arg1,...);
  1672.  
  1673.   $subKey= $Registry->{"Key\\SubKey\\"};
  1674.   $valueData= $Registry->{"Key\\SubKey\\\\ValueName"};
  1675.   $Registry->{"Key\\SubKey\\"}= { "NewSubKey" => {...} };
  1676.   $Registry->{"Key\\SubKey\\\\ValueName"}= "NewValueData";
  1677.   $Registry->{"\\ValueName"}= [ pack("fmt",$data), REG_DATATYPE ];
  1678.  
  1679. =head1 EXAMPLES
  1680.  
  1681.   use Win32::TieRegistry( Delimiter=>"#", ArrayValues=>0 );
  1682.   $pound= $Registry->Delimiter("/");
  1683.   $diskKey= $Registry->{"LMachine/System/Disk/"}
  1684.     or  die "Can't read LMachine/System/Disk key: $^E\n";
  1685.   $data= $key->{"/Information"}
  1686.     or  die "Can't read LMachine/System/Disk//Information value: $^E\n";
  1687.   $remoteKey= $Registry->{"//ServerA/LMachine/System/"}
  1688.     or  die "Can't read //ServerA/LMachine/System/ key: $^E\n";
  1689.   $remoteData= $remoteKey->{"Disk//Information"}
  1690.     or  die "Can't read ServerA's System/Disk//Information value: $^E\n";
  1691.   foreach $entry (  keys(%$diskKey)  ) {
  1692.       ...
  1693.   }
  1694.   foreach $subKey (  $diskKey->SubKeyNames  ) {
  1695.       ...
  1696.   }
  1697.   $diskKey->AllowSave( 1 );
  1698.   $diskKey->RegSaveKey( "C:/TEMP/DiskReg", [] );
  1699.  
  1700. =head1 DESCRIPTION
  1701.  
  1702. The I<Win32::TieRegistry> module lets you manipulate the Registry
  1703. via objects [as in "object oriented"] or via tied hashes.  But
  1704. you will probably mostly use a combination reference, that is, a
  1705. reference to a tied hash that has also been made an object so that
  1706. you can mix both access methods [as shown above].
  1707.  
  1708. If you did not get this module as part of libwin32, you might
  1709. want to get a recent version of libwin32 from CPAN which should
  1710. include this module and the C<Win32API::Registry> module that it
  1711. uses.
  1712.  
  1713. Skip to the L<SUMMARY> section if you just want to dive in and start
  1714. using the Registry from Perl.
  1715.  
  1716. Accessing and manipulating the registry is extremely simple using
  1717. I<Win32::TieRegistry>.  A single, simple expression can return
  1718. you almost any bit of information stored in the Registry.
  1719. I<Win32::TieRegistry> also gives you full access to the "raw"
  1720. underlying API calls so that you can do anything with the Registry
  1721. in Perl that you could do in C.  But the "simple" interface has
  1722. been carefully designed to handle almost all operations itself
  1723. without imposing arbitrary limits while providing sensible
  1724. defaults so you can list only the parameters you care about.
  1725.  
  1726. But first, an overview of the Registry itself.
  1727.  
  1728. =head2 The Registry
  1729.  
  1730. The Registry is a forest:  a collection of several tree structures.
  1731. The root of each tree is a key.  These root keys are identified by
  1732. predefined constants whose names start with "HKEY_".  Although all
  1733. keys have a few attributes associated with each [a class, a time
  1734. stamp, and security information], the most important aspect of keys
  1735. is that each can contain subkeys and can contain values.
  1736.  
  1737. Each subkey has a name:  a string which cannot be blank and cannot
  1738. contain the delimiter character [backslash: C<'\\'>] nor nul
  1739. [C<'\0'>].  Each subkey is also a key and so can contain subkeys
  1740. and values [and has a class, time stamp, and security information].
  1741.  
  1742. Each value has a name:  a string which E<can> be blank and E<can>
  1743. contain the delimiter character [backslash: C<'\\'>] and any
  1744. character except for null, C<'\0'>.  Each value also has data
  1745. associated with it.  Each value's data is a contiguous chunk of
  1746. bytes, which is exactly what a Perl string value is so Perl
  1747. strings will usually be used to represent value data.
  1748.  
  1749. Each value also has a data type which says how to interpret the
  1750. value data.  The primary data types are:
  1751.  
  1752. =over
  1753.  
  1754. =item REG_SZ
  1755.  
  1756. A null-terminated string.
  1757.  
  1758. =item REG_EXPAND_SZ
  1759.  
  1760. A null-terminated string which contains substrings consisting of a
  1761. percent sign [C<'%'>], an environment variable name, then a percent
  1762. sign, that should be replaced with the value associate with that
  1763. environment variable.  The system does I<not> automatically do this
  1764. substitution.
  1765.  
  1766. =item REG_BINARY
  1767.  
  1768. Some arbitrary binary value.  You can think of these as being
  1769. "packed" into a string.
  1770.  
  1771. If your system has the L<SetDualVar> module installed,
  1772. the C<DualBinVals()> option wasn't turned off, and you
  1773. fetch a C<REG_BINARY> value of 4 bytes or fewer, then
  1774. you can use the returned value in a numeric context to
  1775. get at the "unpacked" numeric value.  See C<GetValue()>
  1776. for more information.
  1777.  
  1778. =item REG_MULTI_SZ
  1779.  
  1780. Several null-terminated strings concatenated together with an
  1781. extra trailing C<'\0'> at the end of the list.  Note that the list
  1782. can include empty strings so use the value's length to determine
  1783. the end of the list, not the first occurrence of C<'\0\0'>.
  1784. It is best to set the C<SplitMultis()> option so I<Win32::TieRegistry>
  1785. will split these values into an array of strings for you.
  1786.  
  1787. =item REG_DWORD
  1788.  
  1789. A long [4-byte] integer value.  These values are expected either
  1790. packed into a 4-character string or as a hex string of E<more than>
  1791. 4 characters [but I<not> as a numeric value, unfortunately, as there is
  1792. no sure way to tell a numeric value from a packed 4-byte string that
  1793. just happens to be a string containing a valid numeric value].
  1794.  
  1795. How such values are returned depends on the C<DualBinVals()> and
  1796. C<DWordsToHex()> options.  See C<GetValue()> for details.
  1797.  
  1798. =back
  1799.  
  1800. In the underlying Registry calls, most places which take a
  1801. subkey name also allow you to pass in a subkey "path" -- a
  1802. string of several subkey names separated by the delimiter
  1803. character, backslash [C<'\\'>].  For example, doing
  1804. C<RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\DISK",...)>
  1805. is much like opening the C<"SYSTEM"> subkey of C<HKEY_LOCAL_MACHINE>,
  1806. then opening its "DISK" subkey, then closing the C<"SYSTEM"> subkey.
  1807.  
  1808. All of the I<Win32::TieRegistry> features allow you to use your
  1809. own delimiter in place of the system's delimiter, [C<'\\'>].  In
  1810. most of our examples we will use a forward slash [C<'/'>] as our
  1811. delimiter as it is easier to read and less error prone to use when
  1812. writing Perl code since you have to type two backslashes for each
  1813. backslash you want in a string.  Note that this is true even when
  1814. using single quotes -- C<'\\HostName\LMachine\'> is an invalid
  1815. string and must be written as C<'\\\\HostName\\LMachine\\'>.
  1816.  
  1817. You can also connect to the registry of other computers on your
  1818. network.  This will be discussed more later.
  1819.  
  1820. Although the Registry does not have a single root key, the
  1821. I<Win32::TieRegistry> module creates a virtual root key for you
  1822. which has all of the I<HKEY_*> keys as subkeys.
  1823.  
  1824. =head2 Tied Hashes Documentation
  1825.  
  1826. Before you can use a tied hash, you must create one.  One way to
  1827. do that is via:
  1828.  
  1829.     use Win32::TieRegistry ( TiedHash => '%RegHash' );
  1830.  
  1831. which exports a C<%RegHash> variable into your package and ties it
  1832. to the virtual root key of the Registry.  An alternate method is:
  1833.  
  1834.     my %RegHash;
  1835.     use Win32::TieRegistry ( TiedHash => \%RegHash );
  1836.  
  1837. There are also several ways you can tie a hash variable to any
  1838. other key of the Registry, which are discussed later.
  1839.  
  1840. Note that you will most likely use C<$Registry> instead of using
  1841. a tied hash.  C<$Registry> is a reference to a hash that has
  1842. been tied to the virtual root of your computer's Registry [as if,
  1843. C<$Registry= \%RegHash>].  So you would use C<$Registry-E<gt>{Key}>
  1844. rather than C<$RegHash{Key}> and use C<keys %{$Registry}> rather
  1845. than C<keys %RegHash>, for example.
  1846.  
  1847. For each hash which has been tied to a Registry key, the Perl
  1848. C<keys> function will return a list containing the name of each
  1849. of the key's subkeys with a delimiter character appended to it and
  1850. containing the name of each of the key's values with a delimiter
  1851. prepended to it.  For example:
  1852.  
  1853.     keys( %{ $Registry->{"HKEY_CLASSES_ROOT\\batfile\\"} } )
  1854.  
  1855. might yield the following list value:
  1856.  
  1857.     ( "DefaultIcon\\",  # The subkey named "DefaultIcon"
  1858.       "shell\\",        # The subkey named "shell"
  1859.       "shellex\\",      # The subkey named "shellex"
  1860.       "\\",             # The default value [named ""]
  1861.       "\\EditFlags" )   # The value named "EditFlags"
  1862.  
  1863. For the virtual root key, short-hand subkey names are used as
  1864. shown below.  You can use the short-hand name, the regular
  1865. I<HKEY_*> name, or any numeric value to access these keys, but
  1866. the short-hand names are all that will be returned by the C<keys>
  1867. function.
  1868.  
  1869. =over
  1870.  
  1871. =item "Classes" for HKEY_CLASSES_ROOT
  1872.  
  1873. Contains mappings between file name extensions and the uses
  1874. for such files along with configuration information for COM
  1875. [MicroSoft's Common Object Model] objects.  Usually a link to
  1876. the C<"SOFTWARE\\Classes"> subkey of the C<HKEY_LOCAL_MACHINE>
  1877. key.
  1878.  
  1879. =item "CUser" for HKEY_CURRENT_USER
  1880.  
  1881. Contains information specific to the currently logged-in user.
  1882. Mostly software configuration information.  Usually a link to
  1883. a subkey of the C<HKEY_USERS> key.
  1884.  
  1885. =item "LMachine" for HKEY_LOCAL_MACHINE
  1886.  
  1887. Contains all manner of information about the computer.
  1888.  
  1889. =item "Users" for HKEY_USERS
  1890.  
  1891. Contains one subkey, C<".DEFAULT">, which gets copied to a new
  1892. subkey whenever a new user is added.  Also contains a subkey for
  1893. each user of the system, though only those for active users
  1894. [usually only one] are loaded at any given time.
  1895.  
  1896. =item "PerfData" for HKEY_PERFORMANCE_DATA
  1897.  
  1898. Used to access data about system performance.  Access via this key
  1899. is "special" and all but the most carefully constructed calls will
  1900. fail, usually with C<ERROR_INSUFFICIENT_BUFFER>.  For example, you
  1901. can't enumerate key names without also enumerating values which
  1902. require huge buffers but the exact buffer size required cannot be
  1903. determined beforehand because C<RegQueryInfoKey()> E<always> fails
  1904. with C<ERROR_INSUFFICIENT_BUFFER> for C<HKEY_PERFORMANCE_DATA> no
  1905. matter how it is called.  So it is currently not very useful to
  1906. tie a hash to this key.  You can use it to create an object to use
  1907. for making carefully constructed calls to the underlying Reg*()
  1908. routines.
  1909.  
  1910. =item "CConfig" for HKEY_CURRENT_CONFIG
  1911.  
  1912. Contains minimal information about the computer's current
  1913. configuration that is required very early in the boot process.
  1914. For example, setting for the display adapter such as screen
  1915. resolution and refresh rate are found in here.
  1916.  
  1917. =item "DynData" for HKEY_DYN_DATA
  1918.  
  1919. Dynamic data.  We have found no documentation for this key.
  1920.  
  1921. =back
  1922.  
  1923. A tied hash is much like a regular hash variable in Perl -- you give
  1924. it a key string inside braces, [C<{> and C<}>], and it gives you
  1925. back a value [or lets you set a value].  For I<Win32::TieRegistry>
  1926. hashes, there are two types of values that will be returned.
  1927.  
  1928. =over
  1929.  
  1930. =item SubKeys
  1931.  
  1932. If you give it a string which represents a subkey, then it will
  1933. give you back a reference to a hash which has been tied to that
  1934. subkey.  It can't return the hash itself, so it returns a
  1935. reference to it.  It also blesses that reference so that it is
  1936. also an object so you can use it to call method functions.
  1937.  
  1938. =item Values
  1939.  
  1940. If you give it a string which is a value name, then it will give
  1941. you back a string which is the data for that value.  Alternately,
  1942. you can request that it give you both the data value string and
  1943. the data value type [we discuss how to request this later].  In
  1944. this case, it would return a reference to an array where the value
  1945. data string is element C<[0]> and the value data type is element
  1946. C<[1]>.
  1947.  
  1948. =back
  1949.  
  1950. The key string which you use in the tied hash must be interpreted
  1951. to determine whether it is a value name or a key name or a path
  1952. that combines several of these or even other things.  There are
  1953. two simple rules that make this interpretation easy and
  1954. unambiguous:
  1955.  
  1956.     Put a delimiter after each key name.
  1957.     Put a delimiter in front of each value name.
  1958.  
  1959. Exactly how the key string will be intepreted is governed by the
  1960. following cases, in the order listed.  These cases are designed
  1961. to "do what you mean".  Most of the time you won't have to think
  1962. about them, especially if you follow the two simple rules above.
  1963. After the list of cases we give several examples which should be
  1964. clear enough so feel free to skip to them unless you are worried
  1965. about the details.
  1966.  
  1967. =over
  1968.  
  1969. =item Remote machines
  1970.  
  1971. If the hash is tied to the virtual root of the registry [or the
  1972. virtual root of a remote machine's registry], then we treat hash
  1973. key strings which start with the delimiter character specially.
  1974.  
  1975. If the hash key string starts with two delimiters in a row, then
  1976. those should be immediately followed by the name of a remote
  1977. machine whose registry we wish to connect to.  That can be
  1978. followed by a delimiter and more subkey names, etc.  If the
  1979. machine name is not following by anything, then a virtual root
  1980. for the remote machine's registry is created, a hash is tied to
  1981. it, and a reference to that hash it is returned.
  1982.  
  1983. =item Hash key string starts with the delimiter
  1984.  
  1985. If the hash is tied to a virtual root key, then the leading
  1986. delimiter is ignored.  It should be followed by a valid Registry
  1987. root key name [either a short-hand name like C<"LMachine">, an
  1988. I<HKEY_*> value, or a numeric value].   This alternate notation is
  1989. allowed in order to be more consistant with the C<Open()> method
  1990. function.
  1991.  
  1992. For all other Registry keys, the leading delimiter indicates
  1993. that the rest of the string is a value name.  The leading
  1994. delimiter is stripped and the rest of the string [which can
  1995. be empty and can contain more delimiters] is used as a value
  1996. name with no further parsing.
  1997.  
  1998. =item Exact match with direct subkey name followed by delimiter
  1999.  
  2000. If you have already called the Perl C<keys> function on the tied
  2001. hash [or have already called C<MemberNames> on the object] and the
  2002. hash key string exactly matches one of the strings returned, then
  2003. no further parsing is done.  In other words, if the key string
  2004. exactly matches the name of a direct subkey with a delimiter
  2005. appended, then a reference to a hash tied to that subkey is
  2006. returned [but only if C<keys> or C<MemberNames> has already
  2007. been called for that tied hash].
  2008.  
  2009. This is only important if you have selected a delimiter other than
  2010. the system default delimiter and one of the subkey names contains
  2011. the delimiter you have chosen.  This rule allows you to deal with
  2012. subkeys which contain your chosen delimiter in their name as long
  2013. as you only traverse subkeys one level at a time and always
  2014. enumerate the list of members before doing so.
  2015.  
  2016. The main advantage of this is that Perl code which recursively
  2017. traverses a hash will work on hashes tied to Registry keys even if
  2018. a non-default delimiter has been selected.
  2019.  
  2020. =item Hash key string contains two delimiters in a row
  2021.  
  2022. If the hash key string contains two [or more] delimiters in a row,
  2023. then the string is split between the first pair of delimiters.
  2024. The first part is interpreted as a subkey name or a path of subkey
  2025. names separated by delimiters and with a trailing delimiter.  The
  2026. second part is interpreted as a value name with one leading
  2027. delimiter [any extra delimiters are considered part of the value
  2028. name].
  2029.  
  2030. =item Hash key string ends with a delimiter
  2031.  
  2032. If the key string ends with a delimiter, then it is treated
  2033. as a subkey name or path of subkey names separated by delimiters.
  2034.  
  2035. =item Hash key string contains a delimiter
  2036.  
  2037. If the key string contains a delimiter, then it is split after
  2038. the last delimiter.  The first part is treated as a subkey name or
  2039. path of subkey names separated by delimiters.  The second part
  2040. is ambiguous and is treated as outlined in the next item.
  2041.  
  2042. =item Hash key string contains no delimiters
  2043.  
  2044. If the hash key string contains no delimiters, then it is ambiguous.
  2045.  
  2046. If you are reading from the hash [fetching], then we first use the
  2047. key string as a value name.  If there is a value with a matching
  2048. name in the Registry key which the hash is tied to, then the value
  2049. data string [and possibly the value data type] is returned.
  2050. Otherwise, we retry by using the hash key string as a subkey name.
  2051. If there is a subkey with a matching name, then we return a
  2052. reference to a hash tied to that subkey.  Otherwise we return
  2053. C<undef>.
  2054.  
  2055. If you are writing to the hash [storing], then we use the key
  2056. string as a subkey name only if the value you are storing is a
  2057. reference to a hash value.  Otherwise we use the key string as
  2058. a value name.
  2059.  
  2060. =back
  2061.  
  2062. =head3 Examples
  2063.  
  2064. Here are some examples showing different ways of accessing Registry
  2065. information using references to tied hashes:
  2066.  
  2067. =over
  2068.  
  2069. =item Canonical value fetch
  2070.  
  2071.     $tip18= $Registry->{"HKEY_LOCAL_MACHINE\\Software\\Microsoft\\"
  2072.                . 'Windows\\CurrentVersion\\Explorer\\Tips\\\\18'};
  2073.  
  2074. Should return the text of important tip number 18.  Note that two
  2075. backslashes, C<"\\">, are required to get a single backslash into
  2076. a Perl double-quoted or single-qouted string.  Note that C<"\\">
  2077. is appended to each key name [C<"HKEY_LOCAL_MACHINE"> through
  2078. C<"Tips">] and C<"\\"> is prepended to the value name, C<"18">.
  2079.  
  2080. =item Changing your delimiter
  2081.  
  2082.     $Registry->Delimiter("/");
  2083.     $tip18= $Registry->{"HKEY_LOCAL_MACHINE/Software/Microsoft/"
  2084.                . 'Windows/CurrentVersion/Explorer/Tips//18'};
  2085.  
  2086. This usually makes things easier to read when working in Perl.
  2087. All remaining examples will assume the delimiter has been changed
  2088. as above.
  2089.  
  2090. =item Using intermediate keys
  2091.  
  2092.     $ms= $Registry->{"LMachine/Software/Microsoft/"};
  2093.     $tips= $ms->{"Windows/CurrentVersion/Explorer/Tips/"};
  2094.     $tip18= $winlogon->{"/18"};
  2095.  
  2096. Same as above but opens more keys into the Registry which lets you
  2097. efficiently re-access those intermediate keys.  This is slightly
  2098. less efficient if you never reuse those intermediate keys.
  2099.  
  2100. =item Chaining in a single statement
  2101.  
  2102.     $tip18= $Registry->{"LMachine/Software/Microsoft/"}->
  2103.               {"Windows/CurrentVersion/Explorer/Tips/"}->{"/18"};
  2104.  
  2105. Like above, this creates intermediate key objects then uses
  2106. them to access other data.  Once this statement finishes, the
  2107. intermediate key objects are destroyed.  Several handles into
  2108. the Registry are opened and closed by this statement so it is
  2109. less efficient but there are times when this will be useful.
  2110.  
  2111. =item Even less efficient example of chaining
  2112.  
  2113.     $tip18= $Registry->{"LMachine/Software/Microsoft"}->
  2114.               {"Windows/CurrentVersion/Explorer/Tips"}->{"/18"};
  2115.  
  2116. Because we left off the trailing delimiters, I<Win32::TieRegistry>
  2117. doesn't know whether final names, C<"Microsoft"> and C<"Tips">,
  2118. are subkey names or value names.  So this statement ends up
  2119. executing the same code as the next one.
  2120.  
  2121. =item What the above really does
  2122.  
  2123.     $tip18= $Registry->{"LMachine/Software/"}->{"Microsoft"}->
  2124.               {"Windows/CurrentVersion/Explorer/"}->{"Tips"}->{"/18"};
  2125.  
  2126. With more chains to go through, more temporary objects are created
  2127. and later destroyed than in our first chaining example.  Also,
  2128. when C<"Microsoft"> is looked up, I<Win32::TieRegistry> first
  2129. tries to open it as a value and fails then tries it as a subkey.
  2130. The same is true for when it looks up C<"Tips">.
  2131.  
  2132. =item Getting all of the tips
  2133.  
  2134.     $tips= $Registry->{"LMachine/Software/Microsoft/"}->
  2135.               {"Windows/CurrentVersion/Explorer/Tips/"}
  2136.       or  die "Can't find the Windows tips: $^E\n";
  2137.     foreach(  keys %$tips  ) {
  2138.         print "$_: ", $tips->{$_}, "\n";
  2139.     }
  2140.  
  2141. First notice that we actually check for failure for the first time.
  2142. Note that your version of Perl may not set C<$^E> properly [see
  2143. the L<BUGS> section].  We are assuming that the C<"Tips"> key
  2144. contains no subkeys.  Otherwise the C<print> statement would show
  2145. something like C<"Win32::TieRegistry=HASH(0xc03ebc)"> for each subkey.
  2146.  
  2147. The output from the above code will start something like:
  2148.  
  2149.     /0: If you don't know how to do something,[...]
  2150.  
  2151. =back
  2152.  
  2153. =head3 Deleting items
  2154.  
  2155. You can use the Perl C<delete> function to delete a value from a
  2156. Registry key or to delete a subkey as long that subkey contains
  2157. no subkeys of its own.  See L<More Examples>, below, for more
  2158. information.
  2159.  
  2160. =head3 Storing items
  2161.  
  2162. You can use the Perl assignment operator [C<=>] to create new
  2163. keys, create new values, or replace values.  The values you store
  2164. should be in the same format as the values you would fetch from a
  2165. tied hash.  For example, you can use a single assignment statement
  2166. to copy an entire Registry tree.  The following statement:
  2167.  
  2168.     $Registry->{"LMachine/Software/Classes/Tie_Registry/"}=
  2169.       $Registry->{"LMachine/Software/Classes/batfile/"};
  2170.  
  2171. creates a C<"Tie_Registry"> subkey under the C<"Software\\Classes">
  2172. subkey of the C<HKEY_LOCAL_MACHINE> key.  Then it populates it
  2173. with copies of all of the subkeys and values in the C<"batfile">
  2174. subkey and all of its subkeys.  Note that you need to have
  2175. called C<$Registry-E<gt>ArrayValues(1)> for the proper value data
  2176. type information to be copied.  Note also that this release of
  2177. I<Win32::TieRegistry> does not copy key attributes such as class
  2178. name and security information [this is planned for a future release].
  2179.  
  2180. The following statement creates a whole subtree in the Registry:
  2181.  
  2182.     $Registry->{"LMachine/Software/FooCorp/"}= {
  2183.         "FooWriter/" => {
  2184.             "/Version" => "4.032",
  2185.             "Startup/" => {
  2186.                 "/Title" => "Foo Writer Deluxe ][",
  2187.                 "/WindowSize" => [ pack("LL",$wid,$ht), REG_BINARY ],
  2188.                 "/TaskBarIcon" => [ "0x0001", REG_DWORD ],
  2189.             },
  2190.             "Compatibility/" => {
  2191.                 "/AutoConvert" => "Always",
  2192.                 "/Default Palette" => "Windows Colors",
  2193.             },
  2194.         },
  2195.         "/License", => "0123-9C8EF1-09-FC",
  2196.     };
  2197.  
  2198. Note that all but the last Registry key used on the left-hand
  2199. side of the assignment [that is, "LMachine/Software/" but not
  2200. "FooCorp/"] must already exist for this statement to succeed.
  2201.  
  2202. By using the leading a trailing delimiters on each subkey name and
  2203. value name, I<Win32::TieRegistry> will tell you if you try to assign
  2204. subkey information to a value or visa-versa.
  2205.  
  2206. =head3 More examples
  2207.  
  2208. =over
  2209.  
  2210. =item Adding a new tip
  2211.  
  2212.     $tips= $Registry->{"LMachine/Software/Microsoft/"}->
  2213.               {"Windows/CurrentVersion/Explorer/Tips/"}
  2214.       or  die "Can't find the Windows tips: $^E\n";
  2215.     $tips{'/186'}= "Be very careful when making changes to the Registry!";
  2216.  
  2217. =item Deleting our new tip
  2218.  
  2219.     $tips= $Registry->{"LMachine/Software/Microsoft/"}->
  2220.               {"Windows/CurrentVersion/Explorer/Tips/"}
  2221.       or  die "Can't find the Windows tips: $^E\n";
  2222.     $tip186= delete $tips{'/186'};
  2223.  
  2224. Note that Perl's C<delete> function returns the value that was deleted.
  2225.  
  2226. =item Adding a new tip differently
  2227.  
  2228.     $Registry->{"LMachine/Software/Microsoft/" .
  2229.                 "Windows/CurrentVersion/Explorer/Tips//186"}=
  2230.       "Be very careful when making changes to the Registry!";
  2231.  
  2232. =item Deleting differently
  2233.  
  2234.     $tip186= delete $Registry->{"LMachine/Software/Microsoft/Windows/" .
  2235.                                 "CurrentVersion/Explorer/Tips//186"};
  2236.  
  2237. Note that this only deletes the tail of what we looked up, the
  2238. C<"186"> value, not any of the keys listed.
  2239.  
  2240. =item Deleting a key
  2241.  
  2242. WARNING:  The following code will delete all information about the
  2243. current user's tip preferences.  Actually executing this command
  2244. would probably cause the user to see the Welcome screen the next
  2245. time they log in and may cause more serious problems.  This
  2246. statement is shown as an example only and should not be used when
  2247. experimenting.
  2248.  
  2249.     $tips= delete $Registry->{"CUser/Software/Microsoft/Windows/" .
  2250.                               "CurrentVersion/Explorer/Tips/"};
  2251.  
  2252. This deletes the C<"Tips"> key and the values it contains.  The
  2253. C<delete> function will return a reference to a hash [not a tied
  2254. hash] containing the value names and value data that were deleted.
  2255.  
  2256. The information to be returned is copied from the Registry into a
  2257. regular Perl hash before the key is deleted.  If the key has many
  2258. subkeys, this copying could take a significant amount of memory
  2259. and/or processor time.  So you can disable this process by calling
  2260. the C<FastDelete> member function:
  2261.  
  2262.     $prevSetting= $regKey->FastDelete(1);
  2263.  
  2264. which will cause all subsequent delete operations via C<$regKey>
  2265. to simply return a true value if they succeed.  This optimization
  2266. is automatically done if you use C<delete> in a void context.
  2267.  
  2268. =item Technical notes on deleting
  2269.  
  2270. If you use C<delete> to delete a Registry key or value and use
  2271. the return value, then C<Win32::TieRegistry> usually looks up the
  2272. current contents of that key or value so they can be returned if
  2273. the deletion is successful.  If the deletion succeeds but the
  2274. attempt to lookup the old contents failed, then the return value
  2275. of C<delete> will be C<$^E> from the failed part of the operation.
  2276.  
  2277. =item Undeleting a key
  2278.  
  2279.     $Registry->{"LMachine/Software/Microsoft/Windows/" .
  2280.                 "CurrentVersion/Explorer/Tips/"}= $tips;
  2281.  
  2282. This adds back what we just deleted.  Note that this version of
  2283. I<Win32::TieRegistry> will use defaults for the key attributes
  2284. [such as class name and security] and will not restore the
  2285. previous attributes.
  2286.  
  2287. =item Not deleting a key
  2288.  
  2289. WARNING:  Actually executing the following code could cause
  2290. serious problems.  This statement is shown as an example only and
  2291. should not be used when experimenting.
  2292.  
  2293.     $res= delete $Registry->{"CUser/Software/Microsoft/Windows/"}
  2294.     defined($res)  ||  die "Can't delete URL key: $^E\n";
  2295.  
  2296. Since the "Windows" key should contain subkeys, that C<delete>
  2297. statement should make no changes to the Registry, return C<undef>,
  2298. and set C<$^E> to "Access is denied" [but see the L<BUGS> section
  2299. about C<$^E>].
  2300.  
  2301. =item Not deleting again
  2302.  
  2303.     $tips= $Registry->{"CUser/Software/Microsoft/Windows/" .
  2304.                        "CurrentVersion/Explorer/Tips/"};
  2305.     delete $tips;
  2306.  
  2307. The Perl C<delete> function requires that its argument be an
  2308. expression that ends in a hash element lookup [or hash slice],
  2309. which is not the case here.  The C<delete> function doesn't
  2310. know which hash $tips came from and so can't delete it.
  2311.  
  2312. =back
  2313.  
  2314. =head2 Objects Documentation
  2315.  
  2316. The following member functions are defined for use on
  2317. I<Win32::TieRegistry> objects:
  2318.  
  2319. =over
  2320.  
  2321. =item new
  2322.  
  2323. The C<new> method creates a new I<Win32::TieRegistry> object.
  2324. C<new> is mostly a synonym for C<Open()> so see C<Open()> below for
  2325. information on what arguments to pass in.  Examples:
  2326.  
  2327.     $machKey= new Win32::TieRegistry "LMachine"
  2328.       or  die "Can't access HKEY_LOCAL_MACHINE key: $^E\n";
  2329.     $userKey= Win32::TieRegistry->new("CUser")
  2330.       or  die "Can't access HKEY_CURRENT_USER key: $^E\n";
  2331.  
  2332. Note that calling C<new> via a reference to a tied hash returns
  2333. a simple object, not a reference to a tied hash.
  2334.  
  2335. =item Open
  2336.  
  2337. =item $subKey= $key->Open( $sSubKey, $rhOptions )
  2338.  
  2339. The C<Open> method opens a Registry key and returns a new
  2340. I<Win32::TieRegistry> object associated with that Registry key.
  2341. If C<Open> is called via a reference to a tied hash, then C<Open>
  2342. returns another reference to a tied hash.  Otherwise C<Open>
  2343. returns a simple object and you should then use C<TiedRef> to get
  2344. a reference to a tied hash.
  2345.  
  2346. C<$sSubKey> is a string specifying a subkey to be opened.
  2347. Alternately C<$sSubKey> can be a reference to an array value
  2348. containing the list of increasingly deep subkeys specifying the
  2349. path to the subkey to be opened.
  2350.  
  2351. C<$rhOptions> is an optional reference to a hash containing extra
  2352. options.  The C<Open> method supports two options, C<"Delimiter">
  2353. and C<"Access">, and C<$rhOptions> should have only have zero or
  2354. more of these strings as keys.  See the "Examples" section below
  2355. for more information.
  2356.  
  2357. The C<"Delimiter"> option specifies what string [usually a single
  2358. character] will be used as the delimiter to be appended to subkey
  2359. names and prepended to value names.  If this option is not specified,
  2360. the new key [C<$subKey>] inherits the delimiter of the old key
  2361. [C<$key>].
  2362.  
  2363. The C<"Access"> option specifies what level of access to the
  2364. Registry key you wish to have once it has been opened.  If this
  2365. option is not specified, the new key [C<$subKey>] is opened with
  2366. the same access level used when the old key [C<$key>] was opened.
  2367. The virtual root of the Registry pretends it was opened with
  2368. access C<KEY_READ|KEY_WRITE> so this is the default access when
  2369. opening keys directory via C<$Registry>.  If you don't plan on
  2370. modifying a key, you should open it with C<KEY_READ> access as
  2371. you may not have C<KEY_WRITE> access to it or some of its subkeys.
  2372.  
  2373. If the C<"Access"> option value is a string that starts with
  2374. C<"KEY_">, then it should match E<one> of the predefined access
  2375. levels [probably C<"KEY_READ">, C<"KEY_WRITE">, or
  2376. C<"KEY_ALL_ACCESS">] exported by the C<Win32API::Registry> module.
  2377. Otherwise, a numeric value is expected.  For maximum flexibility,
  2378. include C<use Win32API::Registry qw(:KEY_);>, for example, near
  2379. the top of your script so you can specify more complicated access
  2380. levels such as C<KEY_READ|KEY_WRITE>.
  2381.  
  2382. If C<$sSubKey> does not begin with the delimiter [or C<$sSubKey>
  2383. is an array reference], then the path to the subkey to be opened
  2384. will be relative to the path of the original key [C<$key>].  If
  2385. C<$sSubKey> begins with a single delimiter, then the path to the
  2386. subkey to be opened will be relative to the virtual root of the
  2387. Registry on whichever machine the original key resides.  If
  2388. C<$sSubKey> begins with two consectutive delimiters, then those
  2389. must be followed by a machine name which causes the C<Connect()>
  2390. method function to be called.
  2391.  
  2392. Examples:
  2393.  
  2394.     $machKey= $Registry->Open( "LMachine", {Access=>KEY_READ,Delimiter=>"/"} )
  2395.       or  die "Can't open HKEY_LOCAL_MACHINE key: $^E\n";
  2396.     $swKey= $machKey->Open( "Software" );
  2397.     $logonKey= $swKey->Open( "Microsoft/Windows NT/CurrentVersion/Winlogon/" );
  2398.     $NTversKey= $swKey->Open( ["Microsoft","Windows NT","CurrentVersion"] );
  2399.     $versKey= $swKey->Open( qw(Microsoft Windows CurrentVersion) );
  2400.  
  2401.     $remoteKey= $Registry->Open( "//HostA/LMachine/System/", {Delimiter=>"/"} )
  2402.       or  die "Can't connect to HostA or can't open subkey: $^E\n";
  2403.  
  2404. =item Clone
  2405.  
  2406. =item $copy= $key->Clone
  2407.  
  2408. Creates a new object that is associated with the same Registry key
  2409. as the invoking object.
  2410.  
  2411. =item Connect
  2412.  
  2413. =item $remoteKey= $Registry->Connect( $sMachineName, $sKeyPath, $rhOptions )
  2414.  
  2415. The C<Connect> method connects to the Registry of a remote machine,
  2416. and opens a key within it, then returns a new I<Win32::TieRegistry>
  2417. object associated with that remote Registry key.  If C<Connect>
  2418. was called using a reference to a tied hash, then the return value
  2419. will also be a reference to a tied hash [or C<undef>].  Otherwise,
  2420. if you wish to use the returned object as a tied hash [not just as
  2421. an object], then use the C<TiedRef> method function after C<Connect>.
  2422.  
  2423. C<$sMachineName> is the name of the remote machine.  You don't have
  2424. to preceed the machine name with two delimiter characters.
  2425.  
  2426. C<$sKeyPath> is a string specifying the remote key to be opened.
  2427. Alternately C<$sKeyPath> can be a reference to an array value
  2428. containing the list of increasingly deep keys specifying the path
  2429. to the key to be opened.
  2430.  
  2431. C<$rhOptions> is an optional reference to a hash containing extra
  2432. options.  The C<Connect> method supports two options, C<"Delimiter">
  2433. and C<"Access">.  See the C<Open> method documentation for more
  2434. information on these options.
  2435.  
  2436. C<$sKeyPath> is already relative to the virtual root of the Registry
  2437. of the remote machine.  A single leading delimiter on C<sKeyPath>
  2438. will be ignored and is not required.
  2439.  
  2440. C<$sKeyPath> can be empty in which case C<Connect> will return an
  2441. object representing the virtual root key of the remote Registry.
  2442. Each subsequent use of C<Open> on this virtual root key will call
  2443. the system C<RegConnectRegistry> function.
  2444.  
  2445. The C<Connect> method can be called via any I<Win32::TieRegistry>
  2446. object, not just C<$Registry>.  Attributes such as the desired
  2447. level of access and the delimiter will be inherited from the
  2448. object used but the C<$sKeyPath> will always be relative to the
  2449. virtual root of the remote machine's registry.
  2450.  
  2451. Examples:
  2452.  
  2453.     $remMachKey= $Registry->Connect( "HostA", "LMachine", {Delimiter->"/"} )
  2454.       or  die "Can't connect to HostA's HKEY_LOCAL_MACHINE key: $^E\n";
  2455.  
  2456.     $remVersKey= $remMachKey->Connect( "www.microsoft.com",
  2457.                    "LMachine/Software/Microsoft/Inetsrv/CurrentVersion/",
  2458.                    { Access->KEY_READ, Delimiter->"/" } )
  2459.       or  die "Can't check what version of IIS Microsoft is running: $^E\n";
  2460.  
  2461.     $remVersKey= $remMachKey->Connect( "www",
  2462.                    qw(LMachine Software Microsoft Inetsrv CurrentVersion) )
  2463.       or  die "Can't check what version of IIS we are running: $^E\n";
  2464.  
  2465. =item ObjectRef
  2466.  
  2467. =item $object_ref= $obj_or_hash_ref->ObjectRef
  2468.  
  2469. For a simple object, just returns itself [C<$obj == $obj->ObjectRef>].
  2470.  
  2471. For a reference to a tied hash [if it is also an object], C<ObjectRef>
  2472. returns the simple object that the hash is tied to.
  2473.  
  2474. This is primarilly useful when debugging since typing C<x $Registry>
  2475. will try to display your I<entire> registry contents to your screen.
  2476. But the debugger command C<x $Registry->ObjectRef> will just dump
  2477. the implementation details of the underlying object to your screen.
  2478.  
  2479. =item Flush( $bFlush )
  2480.  
  2481. Flushes all cached information about the Registry key so that future
  2482. uses will get fresh data from the Registry.
  2483.  
  2484. If the optional C<$bFlush> is specified and a true value, then
  2485. C<RegFlushKey()> will be called, which is almost never necessary.
  2486.  
  2487. =item GetValue
  2488.  
  2489. =item $ValueData= $key->GetValue( $sValueName )
  2490.  
  2491. =item ($ValueData,$ValueType)= $key->GetValue( $sValueName )
  2492.  
  2493. Gets a Registry value's data and data type.
  2494.  
  2495. C<$ValueData> is usually just a Perl string that contains the
  2496. value data [packed into it].  For certain types of data, however,
  2497. C<$ValueData> may be processed as described below.
  2498.  
  2499. C<$ValueType> is the C<REG_*> constant describing the type of value
  2500. data stored in C<$ValueData>.  If the C<DualTypes()> option is on,
  2501. then C<$ValueType> will be a dual value.  That is, when used in a
  2502. numeric context, C<$ValueType> will give the numeric value of a
  2503. C<REG_*> constant.  However, when used in a non-numeric context,
  2504. C<$ValueType> will return the name of the C<REG_*> constant, for
  2505. example C<"REG_SZ"> [note the quotes].  So both of the following
  2506. can be true at the same time:
  2507.  
  2508.     $ValueType == REG_SZ
  2509. and
  2510.     $ValueType eq "REG_SZ"
  2511.  
  2512. =over
  2513.  
  2514. =item REG_SZ and REG_EXPAND_SZ
  2515.  
  2516. If the C<FixSzNulls()> option is on, then the trailing C<'\0'> will be
  2517. stripped [unless there isn't one] before values of type C<REG_SZ>
  2518. and C<REG_EXPAND_SZ> are returned.  Note that C<SetValue()> will add
  2519. a trailing C<'\0'> under similar circumstances.
  2520.  
  2521. =item REG_MULTI_SZ
  2522.  
  2523. If the C<SplitMultis()> option is on, then values of this type are
  2524. returned as a reference to an array containing the strings.  For
  2525. example, a value that, with C<SplitMultis()> off, would be returned as:
  2526.  
  2527.     "Value1\000Value2\000\000"
  2528.  
  2529. would be returned, with C<SplitMultis()> on, as:
  2530.  
  2531.     [ "Value1", "Value2" ]
  2532.  
  2533. =item REG_DWORD
  2534.  
  2535. If the C<DualBinVals()> option is on, then the value is returned
  2536. as a scalar containing both a string and a number [much like
  2537. the C<$!> variable -- see the C<SetDualVar()> module for more
  2538. information] where the number part is the "unpacked" value.
  2539. Use the returned value in a numeric context to access this part
  2540. of the value.  For example:
  2541.  
  2542.     $num= 0 + $Registry->{"CUser/Console//ColorTable01"};
  2543.  
  2544. If the C<DWordsToHex()> option is off, the string part of the
  2545. returned value is a packed, 4-byte string [use C<unpack("L",$value)>
  2546. to get the numeric value.
  2547.  
  2548. If C<DWordsToHex()> is on, the string part of the returned value is
  2549. a 10-character hex strings [with leading "0x"].  You can use
  2550. C<hex($value)> to get the numeric value.
  2551.  
  2552. Note that C<SetValue()> will properly understand each of these
  2553. returned value formats no matter how C<DualBinVals()> is set.
  2554.  
  2555. =back
  2556.  
  2557. =item ValueNames
  2558.  
  2559. =item @names= $key->ValueNames
  2560.  
  2561. Returns the list of value names stored directly in a Registry key.
  2562. Note that the names returned do I<not> have a delimiter prepended
  2563. to them like with C<MemberNames()> and tied hashes.
  2564.  
  2565. Once you request this information, it is cached in the object and
  2566. future requests will always return the same list unless C<Flush()>
  2567. has been called.
  2568.  
  2569. =item SubKeyNames
  2570.  
  2571. =item @key_names= $key->SubKeyNames
  2572.  
  2573. Returns the list of subkey names stored directly in a Registry key.
  2574. Note that the names returned do I<not> have a delimiter appended
  2575. to them like with C<MemberNames()> and tied hashes.
  2576.  
  2577. Once you request this information, it is cached in the object and
  2578. future requests will always return the same list unless C<Flush()>
  2579. has been called.
  2580.  
  2581. =item SubKeyClasses
  2582.  
  2583. =item @classes= $key->SubKeyClasses
  2584.  
  2585. Returns the list of classes for subkeys stored directly in a
  2586. Registry key.  The classes are returned in the same order as
  2587. the subkey names returned by C<SubKeyNames()>.
  2588.  
  2589. =item SubKeyTimes
  2590.  
  2591. =item @times= $key->SubKeyTimes
  2592.  
  2593. Returns the list of last-modified times for subkeys stored
  2594. directly in a Registry key.  The times are returned in the same
  2595. order as the subkey names returned by C<SubKeyNames()>.  Each
  2596. time is a C<FILETIME> structure packed into a Perl string.
  2597.  
  2598. Once you request this information, it is cached in the object and
  2599. future requests will always return the same list unless C<Flush()>
  2600. has been called.
  2601.  
  2602. =item MemberNames
  2603.  
  2604. =item @members= $key->MemberNames
  2605.  
  2606. Returns the list of subkey names and value names stored directly
  2607. in a Registry key.  Subkey names have a delimiter appended to the
  2608. end and value names have a delimiter prepended to the front.
  2609.  
  2610. Note that a value name could end in a delimiter [or could be C<"">
  2611. so that the member name returned is just a delimiter] so the
  2612. presence or absence of the leading delimiter is what should be
  2613. used to determine whether a particular name is for a subkey or a
  2614. value, not the presence or absence of a trailing delimiter.
  2615.  
  2616. Once you request this information, it is cached in the object and
  2617. future requests will always return the same list unless C<Flush()>
  2618. has been called.
  2619.  
  2620. =item Information
  2621.  
  2622. =item %info= $key->Information
  2623.  
  2624. =item @items= $key->Information( @itemNames );
  2625.  
  2626. Returns the following information about a Registry key:
  2627.  
  2628. =over
  2629.  
  2630. =item LastWrite
  2631.  
  2632. A C<FILETIME> structure indicating when the key was last modified
  2633. and packed into a Perl string.
  2634.  
  2635. =item CntSubKeys
  2636.  
  2637. The number of subkeys stored directly in this key.
  2638.  
  2639. =item CntValues
  2640.  
  2641. The number of values stored directly in this key.
  2642.  
  2643. =item SecurityLen
  2644.  
  2645. The length [in bytes] of the largest[?] C<SECURITY_DESCRIPTOR>
  2646. associated with the Registry key.
  2647.  
  2648. =item MaxValDataLen
  2649.  
  2650. The length [in bytes] of the longest value data associated with
  2651. a value stored in this key.
  2652.  
  2653. =item MaxSubKeyLen
  2654.  
  2655. The length [in chars] of the longest subkey name associated with
  2656. a subkey stored in this key.
  2657.  
  2658. =item MaxSubClassLen
  2659.  
  2660. The length [in chars] of the longest class name associated with
  2661. a subkey stored directly in this key.
  2662.  
  2663. =item MaxValNameLen
  2664.  
  2665. The length [in chars] of the longest value name associated with
  2666. a value stored in this key.
  2667.  
  2668. =back
  2669.  
  2670. With no arguments, returns a hash [not a reference to a hash] where
  2671. the keys are the names for the items given above and the values
  2672. are the information describe above.  For example:
  2673.  
  2674.     %info= ( "CntValues" => 25,         # Key contains 25 values.
  2675.              "MaxValNameLen" => 20,     # One of which has a 20-char name.
  2676.              "MaxValDataLen" => 42,     # One of which has a 42-byte value.
  2677.              "CntSubKeys" => 1,         # Key has 1 immediate subkey.
  2678.              "MaxSubKeyLen" => 13,      # One of which has a 12-char name.
  2679.              "MaxSubClassLen" => 0,     # All of which have class names of "".
  2680.              "SecurityLen" => 232,      # One SECURITY_DESCRIPTOR is 232 bytes.
  2681.              "LastWrite" => "\x90mZ\cX{\xA3\xBD\cA\c@\cA"
  2682.                    # Key was last modifed 1998/06/01 16:29:32 GMT
  2683.            );
  2684.  
  2685. With arguments, each one must be the name of a item given above.
  2686. The return value is the information associated with the listed
  2687. names.  In other words:
  2688.  
  2689.     return $key->Information( @names );
  2690.  
  2691. returns the same list as:
  2692.  
  2693.     %info= $key->Information;
  2694.     return @info{@names};
  2695.  
  2696. =item Delimiter
  2697.  
  2698. =item $oldDelim= $key->Delimiter
  2699.  
  2700. =item $oldDelim= $key->Delimiter( $newDelim )
  2701.  
  2702. Gets and possibly changes the delimiter used for this object.  The
  2703. delimiter is appended to subkey names and prepended to value names
  2704. in many return values.  It is also used when parsing keys passed
  2705. to tied hashes.
  2706.  
  2707. The delimiter defaults to backslash (C<'\\'>) but is inherited from
  2708. the object used to create a new object and can be specified by an
  2709. option when a new object is created.
  2710.  
  2711. =item Handle
  2712.  
  2713. =item $handle= $key->Handle
  2714.  
  2715. Returns the raw C<HKEY> handle for the associated Registry key as
  2716. an integer value.  This value can then be used to Reg*() calls
  2717. from C<Win32API::Registry>.  However, it is usually easier to just
  2718. call the C<Win32API::Registry> calls directly via:
  2719.  
  2720.     $key->RegNotifyChangeKeyValue( ... );
  2721.  
  2722. For the virtual root of the local or a remote Registry,
  2723. C<Handle()> return C<"NONE">.
  2724.  
  2725. =item Path
  2726.  
  2727. =item $path= $key->Path
  2728.  
  2729. Returns a string describing the path of key names to this
  2730. Registry key.  The string is built so that if it were passed
  2731. to C<$Registry->Open()>, it would reopen the same Registry key
  2732. [except in the rare case where one of the key names contains
  2733. C<$key->Delimiter>].
  2734.  
  2735. =item Machine
  2736.  
  2737. =item $computerName= $key->Machine
  2738.  
  2739. Returns the name of the computer [or "machine"] on which this Registry
  2740. key resides.  Returns C<""> for local Registry keys.
  2741.  
  2742. =item Access
  2743.  
  2744. Returns the numeric value of the bit mask used to specify the
  2745. types of access requested when this Registry key was opened.  Can
  2746. be compared to C<KEY_*> values.
  2747.  
  2748. =item OS_Delimiter
  2749.  
  2750. Returns the delimiter used by the operating system's RegOpenKeyEx()
  2751. call.  For Win32, this is always backslash (C<"\\">).
  2752.  
  2753. =item Roots
  2754.  
  2755. Returns the mapping from root key names like C<"LMachine"> to their
  2756. associated C<HKEY_*> constants.  Primarily for internal use and
  2757. subject to change.
  2758.  
  2759. =item Tie
  2760.  
  2761. =item $key->Tie( \%hash );
  2762.  
  2763. Ties the referenced hash to that Registry key.  Pretty much the
  2764. same as
  2765.  
  2766.     tie %hash, ref($key), $key;
  2767.  
  2768. Since C<ref($key)> is the class [package] to tie the hash to and
  2769. C<TIEHASH()> just returns its argument, C<$key>, [without calling
  2770. C<new()>] when it sees that it is already a blessed object.
  2771.  
  2772. =item TiedRef
  2773.  
  2774. =item $TiedHashRef= $hash_or_obj_ref->TiedRef
  2775.  
  2776. For a simple object, returns a reference to a hash tied to the
  2777. object.  Used to promote a simple object into a combined object
  2778. and hash ref.
  2779.  
  2780. If already a reference to a tied hash [that is also an object],
  2781. it just returns itself [C<$ref == $ref->TiedRef>].
  2782.  
  2783. Mostly used internally.
  2784.  
  2785. =item ArrayValues
  2786.  
  2787. =item $oldBool= $key->ArrayValues
  2788.  
  2789. =item $oldBool= $key->ArrayValues( $newBool )
  2790.  
  2791. Gets the current setting of the C<ArrayValues> option and possibly
  2792. turns it on or off.
  2793.  
  2794. When off, Registry values fetched via a tied hash are returned as
  2795. just a value scalar [the same as C<GetValue()> in a scalar context].
  2796. When on, they are returned as a reference to an array containing
  2797. the value data as the C<[0]> element and the data type as the C<[1]>
  2798. element.
  2799.  
  2800. =item TieValues
  2801.  
  2802. =item $oldBool= TieValues
  2803.  
  2804. =item $oldBool= TieValues( $newBool )
  2805.  
  2806. Gets the current setting of the C<TieValues> option and possibly
  2807. turns it on or off.
  2808.  
  2809. Turning this option on is not yet supported in this release of
  2810. C<Win32::TieRegistry>.  In a future release, turning this option
  2811. on will cause Registry values returned from a tied hash to be
  2812. a tied array that you can use to modify the value in the Registry.
  2813.  
  2814. =item FastDelete
  2815.  
  2816. =item $oldBool= $key->FastDelete
  2817.  
  2818. =item $oldBool= $key->FastDelete( $newBool )
  2819.  
  2820. Gets the current setting of the C<FastDelete> option and possibly
  2821. turns it on or off.
  2822.  
  2823. When on, successfully deleting a Registry key [via a tied hash]
  2824. simply returns C<1>.
  2825.  
  2826. When off, successfully deleting a Registry key [via a tied hash
  2827. and not in a void context] returns a reference to a hash that
  2828. contains the values present in the key when it was deleted.  This
  2829. hash is just like that returned when referencing the key before it
  2830. was deleted except that it is an ordinary hash, not one tied to
  2831. the C<Win32::TieRegistry> package.
  2832.  
  2833. Note that deleting either a Registry key or value via a tied hash
  2834. I<in a void context> prevents any overhead in trying to build an
  2835. appropriate return value.
  2836.  
  2837. Note that deleting a Registry I<value> via a tied hash [not in
  2838. a void context] returns the value data even if <FastDelete> is on.
  2839.  
  2840. =item SplitMultis
  2841.  
  2842. =item $oldBool= $key->SplitMultis
  2843.  
  2844. =item $oldBool= $key->SplitMultis( $newBool )
  2845.  
  2846. Gets the current setting of the C<SplitMultis> option and possibly
  2847. turns it on or off.
  2848.  
  2849. If on, Registry values of type C<REG_MULTI_SZ> are returned as
  2850. a reference to an array of strings.  See C<GetValue()> for more
  2851. information.
  2852.  
  2853. =item DWordsToHex
  2854.  
  2855. =item $oldBool= $key->DWordsToHex
  2856.  
  2857. =item $oldBool= $key->DWordsToHex( $newBool )
  2858.  
  2859. Gets the current setting of the C<DWordsToHex> option and possibly
  2860. turns it on or off.
  2861.  
  2862. If on, Registry values of type C<REG_DWORD> are returned as a hex
  2863. string with leading C<"0x"> and longer than 4 characters.  See
  2864. C<GetValue()> for more information.
  2865.  
  2866. =item FixSzNulls
  2867.  
  2868. =item $oldBool= $key->FixSzNulls
  2869.  
  2870. =item $oldBool= $key->FixSzNulls( $newBool )
  2871.  
  2872. Gets the current setting of the C<FixSzNulls> option and possibly
  2873. turns it on or off.
  2874.  
  2875. If on, Registry values of type C<REG_SZ> and C<REG_EXPAND_SZ> have
  2876. trailing C<'\0'>s added before they are set and stripped before
  2877. they are returned.  See C<GetValue()> and C<SetValue()> for more
  2878. information.
  2879.  
  2880. =item DualTypes
  2881.  
  2882. =item $oldBool= $key->DualTypes
  2883.  
  2884. =item $oldBool= $key->DualTypes( $newBool )
  2885.  
  2886. Gets the current setting of the C<DualTypes> option and possibly
  2887. turns it on or off.
  2888.  
  2889. If on, data types are returned as a combined numeric/string value
  2890. holding both the numeric value of a C<REG_*> constant and the
  2891. string value of the constant's name.  See C<GetValue()> for
  2892. more information.
  2893.  
  2894. =item DualBinVals
  2895.  
  2896. =item $oldBool= $key->DualBinVals
  2897.  
  2898. =item $oldBool= $key->DualBinVals( $newBool )
  2899.  
  2900. Gets the current setting of the C<DualBinVals> option and possibly
  2901. turns it on or off.
  2902.  
  2903. If on, Registry value data of type C<REG_BINARY> and no more than
  2904. 4 bytes long and Registry values of type C<REG_DWORD> are returned
  2905. as a combined numeric/string value where the numeric value is the
  2906. "unpacked" binary value as returned by:
  2907.  
  2908.     hex reverse unpack( "h*", $valData )
  2909.  
  2910. on a "little-endian" computer.  [Would be C<hex unpack("H*",$valData)>
  2911. on a "big-endian" computer if this module is ever ported to one.]
  2912.  
  2913. See C<GetValue()> for more information.
  2914.  
  2915. =item GetOptions
  2916.  
  2917. =item @oldOpts= $key->GetOptions( @optionNames )
  2918.  
  2919. Returns the current setting of any of the following options:
  2920.  
  2921.     Delimiter     FixSzNulls    DWordsToHex
  2922.     ArrayValues   SplitMultis   DualBinVals
  2923.     TieValues     FastDelete    DualTypes
  2924.  
  2925. =item SetOptions
  2926.  
  2927. =item @oldOpts= $key->SetOptions( optNames=>$optValue,... )
  2928.  
  2929. Changes the current setting of any of the following options,
  2930. returning the previous setting(s):
  2931.  
  2932.     Delimiter     FixSzNulls    DWordsToHex   AllowLoad
  2933.     ArrayValues   SplitMultis   DualBinVals   AllowSave
  2934.     TieValues     FastDelete    DualTypes
  2935.  
  2936. For C<AllowLoad> and C<AllowSave>, instead of the previous
  2937. setting, C<SetOptions> returns whether or not the change was
  2938. successful.
  2939.  
  2940. In a scalar context, returns only the last item.  The last
  2941. option can also be specified as C<"ref"> or C<"r"> [which doesn't
  2942. need to be followed by a value] to allow chaining:
  2943.  
  2944.     $key->SetOptions(AllowSave=>1,"ref")->RegSaveKey(...)
  2945.  
  2946. =item SetValue
  2947.  
  2948. =item $okay= $key->SetValue( $ValueName, $ValueData );
  2949.  
  2950. =item $okay= $key->SetValue( $ValueName, $ValueData, $ValueType );
  2951.  
  2952. Adds or replaces a Registry value.  Returns a true value if
  2953. successfully, false otherwise.
  2954.  
  2955. C<$ValueName> is the name of the value to add or replace and
  2956. should I<not> have a delimiter prepended to it.  Case is ignored.
  2957.  
  2958. C<$ValueType> is assumed to be C<REG_SZ> if it is omitted.  Otherwise,
  2959. it should be one the C<REG_*> constants.
  2960.  
  2961. C<$ValueData> is the data to be stored in the value, probably packed
  2962. into a Perl string.  Other supported formats for value data are
  2963. listed below for each posible C<$ValueType>.
  2964.  
  2965. =over
  2966.  
  2967. =item REG_SZ or REG_EXPAND_SZ
  2968.  
  2969. The only special processing for these values is the addition of
  2970. the required trailing C<'\0'> if it is missing.  This can be
  2971. turned off by disabling the C<FixSzNulls> option.
  2972.  
  2973. =item REG_MULTI_SZ
  2974.  
  2975. These values can also be specified as a reference to a list of
  2976. strings.  For example, the following two lines are equivalent:
  2977.  
  2978.     $key->SetValue( "Val1\000Value2\000LastVal\000\000", REG_MULTI_SZ );
  2979. vs.
  2980.     $key->SetValue( ["Val1","Value2","LastVal"], REG_MULTI_SZ );
  2981.  
  2982. Note that if the required two trailing nulls (C<"\000\000">) are
  2983. missing, then this release of C<SetValue()> will I<not> add them.
  2984.  
  2985. =item REG_DWORD
  2986.  
  2987. These values can also be specified as a hex value with the leading
  2988. C<"0x"> included and totaling I<more than> 4 bytes.  These will be
  2989. packed into a 4-byte string via:
  2990.  
  2991.     $data= pack( "L", hex($data) );
  2992.  
  2993. =item REG_BINARY
  2994.  
  2995. This value type is listed just to emphasize that no alternate
  2996. format is supported for it.  In particular, you should I<not> pass
  2997. in a numeric value for this type of data.  C<SetValue()> cannot
  2998. distinguish such from a packed string that just happens to match
  2999. a numeric value and so will treat it as a packed string.
  3000.  
  3001. =back
  3002.  
  3003. An alternate calling format:
  3004.  
  3005.     $okay= $key->SetValue( $ValueName, [ $ValueData, $ValueType ] );
  3006.  
  3007. [two arguments, the second of which is a reference to an array
  3008. containing the value data and value type] is supported to ease
  3009. using tied hashes with C<SetValue()>.
  3010.  
  3011. =item CreateKey
  3012.  
  3013. =item $newKey= $key->CreateKey( $subKey );
  3014.  
  3015. =item $newKey= $key->CreateKey( $subKey, { Option=>OptVal,... } );
  3016.  
  3017. Creates a Registry key or just updates attributes of one.  Calls
  3018. C<RegCreateKeyEx()> then, if it succeeded, creates an object
  3019. associated with the [possibly new] subkey.
  3020.  
  3021. C<$subKey> is the name of a subkey [or a path to one] to be
  3022. created or updated.  It can also be a reference to an array
  3023. containing a list of subkey names.
  3024.  
  3025. The second argument, if it exists, should be a reference to a
  3026. hash specifying options either to be passed to C<RegCreateKeyEx()>
  3027. or to be used when creating the associated object.  The following
  3028. items are the supported keys for this options hash:
  3029.  
  3030. =over
  3031.  
  3032. =item Delimiter
  3033.  
  3034. Specifies the delimiter to be used to parse C<$subKey> and to be
  3035. used in the new object.  Defaults to C<$key->Delimiter>.
  3036.  
  3037. =item Access
  3038.  
  3039. Specifies the types of access requested when the subkey is opened.
  3040. Should be a numeric bit mask that combines one or more C<KEY_*>
  3041. constant values.
  3042.  
  3043. =item Class
  3044.  
  3045. The name to assign as the class of the new or updated subkey.
  3046. Defaults to C<""> as we have never seen a use for this information.
  3047.  
  3048. =item Disposition
  3049.  
  3050. Lets you specify a reference to a scalar where, upon success,
  3051. either C<REG_CREATED_NEW_KEY> or C<REG_OPENED_EXISTING_KEY>
  3052. depending on whether a new key was created or an existing key
  3053. was opened.
  3054.  
  3055. =item Security
  3056.  
  3057. Lets you specify a C<SECURITY_ATTRIBUTES> structure packed into a
  3058. Perl string.  See C<Win32API::Registry::RegCreateKeyEx()> for more
  3059. information.
  3060.  
  3061. =item Volatile
  3062.  
  3063. If true, specifies that the new key should be volatile, that is,
  3064. stored only in memory and not backed by a hive file [and not saved
  3065. if the computer is rebooted].  This option is ignored under
  3066. Windows 95.  Specifying C<Volatile=E<GT>1>  is the same as
  3067. specifying C<Options=E<GT>REG_OPTION_VOLATILE>.
  3068.  
  3069. =item Backup
  3070.  
  3071. If true, specifies that the new key should be opened for
  3072. backup/restore access.  The C<Access> option is ignored.  If the
  3073. calling process has enabled C<"SeBackupPrivilege">, then the
  3074. subkey is opened with C<KEY_READ> access as the C<"LocalSystem">
  3075. user which should have access to all subkeys.  If the calling
  3076. process has enabled C<"SeRestorePrivilege">, then the subkey is
  3077. opened with C<KEY_WRITE> access as the C<"LocalSystem"> user which
  3078. should have access to all subkeys.
  3079.  
  3080. This option is ignored under Windows 95.  Specifying C<Backup=E<GT>1>
  3081. is the same as specifying C<Options=E<GT>REG_OPTION_BACKUP_RESTORE>.
  3082.  
  3083. =item Options
  3084.  
  3085. Lets you specify options to the C<RegOpenKeyEx()> call.  The value
  3086. for this option should be a numeric value combining zero or more
  3087. of the C<REG_OPTION_*> bit masks.  You may with to used the
  3088. C<Volatile> and/or C<Backup> options instead of this one.
  3089.  
  3090. =back
  3091.  
  3092. =item StoreKey
  3093.  
  3094. =item $newKey= $key->StoreKey( $subKey, \%Contents );
  3095.  
  3096. Primarily for internal use.
  3097.  
  3098. Used to create or update a Registry key and any number of subkeys
  3099. or values under it or its subkeys.
  3100.  
  3101. C<$subKey> is the name of a subkey to be created [or a path of
  3102. subkey names separated by delimiters].  If that subkey already
  3103. exists, then it is updated.
  3104.  
  3105. C<\%Contents> is a reference to a hash containing pairs of
  3106. value names with value data and/or subkey names with hash
  3107. references similar to C<\%Contents>.  Each of these cause
  3108. a value or subkey of C<$subKey> to be created or updated.
  3109.  
  3110. If C<$Contents{""}> exists and is a reference to a hash, then
  3111. it used as the options argument when C<CreateKey()> is called
  3112. for C<$subKey>.  This allows you to specify ...
  3113.  
  3114.     if(  defined( $$data{""} )  &&  "HASH" eq ref($$data{""})  ) {
  3115.     $self= $this->CreateKey( $subKey, delete $$data{""} );
  3116.  
  3117. =item Load
  3118.  
  3119. =item $newKey= $key->Load( $file )
  3120.  
  3121. =item $newKey= $key->Load( $file, $newSubKey )
  3122.  
  3123. =item $newKey= $key->Load( $file, $newSubKey, { Option=>OptVal... } )
  3124.  
  3125. =item $newKey= $key->Load( $file, { Option=>OptVal... } )
  3126.  
  3127. Loads a hive file into a Registry.  That is, creates a new subkey
  3128. and associates a hive file with it.
  3129.  
  3130. C<$file> is a hive file, that is a file created by calling
  3131. C<RegSaveKey()>.  The C<$file> path is interpreted relative to
  3132. C<%SystemRoot%/System32/config> on the machine where C<$key>
  3133. resides.
  3134.  
  3135. C<$newSubKey> is the name to be given to the new subkey.  If
  3136. C<$newSubKey> is specified, then C<$key> must be
  3137. C<HKEY_LOCAL_MACHINE> or C<HKEY_USERS> of the local computer
  3138. or a remote computer and C<$newSubKey> should not contain any
  3139. occurrences of either the delimiter or the OS delimiter.
  3140.  
  3141. If C<$newSubKey> is not specified, then it is as if C<$key>
  3142. was C<$Registry-E<GT>{LMachine}> and C<$newSubKey> is
  3143. C<"PerlTie:999"> where C<"999"> is actually a sequence number
  3144. incremented each time this process calls C<Load()>.
  3145.  
  3146. You can specify as the last argument a reference to a hash
  3147. containing options.  You can specify the same options that you
  3148. can specify to C<Open()>.  See C<Open()> for more information on
  3149. those.  In addition, you can specify the option C<"NewSubKey">.
  3150. The value of this option is interpretted exactly as if it was
  3151. specified as the C<$newSubKey> parameter and overrides the
  3152. C<$newSubKey> if one was specified.
  3153.  
  3154. =item UnLoad
  3155.  
  3156. =item $okay= $key->UnLoad
  3157.  
  3158. Unloads a hive that was loaded via C<Load()>.  Cannot unload other
  3159. hives.  C<$key> must be the return from a previous call to C<Load()>.
  3160. C<$key> is closed and then the hive is unloaded.
  3161.  
  3162. =item AllowSave
  3163.  
  3164. =item $okay= AllowSave( $bool )
  3165.  
  3166. Enables or disables the C<"ReBackupPrivilege"> privilege for the
  3167. current process.  You will probably have to enable this privilege
  3168. before you can use C<RegSaveKey()>.
  3169.  
  3170. The return value indicates whether the operation succeeded, not
  3171. whether the privilege was previously enabled.
  3172.  
  3173. =item AllowLoad
  3174.  
  3175. =item $okay= AllowLoad( $bool )
  3176.  
  3177. Enables or disables the C<"ReRestorePrivilege"> privilege for the
  3178. current process.  You will probably have to enable this privilege
  3179. before you can use C<RegLoadKey()>, C<RegUnLoadKey()>,
  3180. C<RegReplaceKey()>, or C<RegRestoreKey> and thus C<Load()> and
  3181. C<UnLoad()>.
  3182.  
  3183. The return value indicates whether the operation succeeded, not
  3184. whether the privilege was previously enabled.
  3185.  
  3186. =back
  3187.  
  3188. =head1 SUMMARY
  3189.  
  3190. Most things can be done most easily via tied hashes.  Skip down to the
  3191. the L<Tied Hashes Summary> to get started quickly.
  3192.  
  3193. =head2 Objects Summary
  3194.  
  3195. Here are quick examples that document the most common functionality
  3196. of all of the method functions [except for a few almost useless ones].
  3197.  
  3198.     # Just another way of saying Open():
  3199.     $key= new Win32::TieRegistry "LMachine\\Software\\",
  3200.       { Access=>KEY_READ|KEY_WRITE, Delimiter=>"\\" };
  3201.  
  3202.     # Open a Registry key:
  3203.     $subKey= $key->Open( "SubKey/SubSubKey/",
  3204.       { Access=>KEY_ALL_ACCESS, Delimiter=>"/" } );
  3205.  
  3206.     # Connect to a remote Registry key:
  3207.     $remKey= $Registry->Connect( "MachineName", "LMachine/",
  3208.       { Access=>KEY_READ, Delimiter=>"/" } );
  3209.  
  3210.     # Get value data:
  3211.     $valueString= $key->GetValue("ValueName");
  3212.     ( $valueString, $valueType )= $key->GetValue("ValueName");
  3213.  
  3214.     # Get list of value names:
  3215.     @valueNames= $key->ValueNames;
  3216.  
  3217.     # Get list of subkey names:
  3218.     @subKeyNames= $key->SubKeyNames;
  3219.  
  3220.     # Get combined list of value names (with leading delimiters)
  3221.     # and subkey names (with trailing delimiters):
  3222.     @memberNames= $key->MemberNames;
  3223.  
  3224.     # Get all information about a key:
  3225.     %keyInfo= $key->Information;
  3226.     # keys(%keyInfo)= qw( Class LastWrite SecurityLen
  3227.     #   CntSubKeys MaxSubKeyLen MaxSubClassLen
  3228.     #   CntValues MaxValNameLen MaxValDataLen );
  3229.  
  3230.     # Get selected information about a key:
  3231.     ( $class, $cntSubKeys )= $key->Information( "Class", "CntSubKeys" );
  3232.  
  3233.     # Get and/or set delimiter:
  3234.     $delim= $key->Delimiter;
  3235.     $oldDelim= $key->Delimiter( $newDelim );
  3236.  
  3237.     # Get "path" for an open key:
  3238.     $path= $key->Path;
  3239.     # For example, "/CUser/Control Panel/Mouse/"
  3240.     # or "//HostName/LMachine/System/DISK/".
  3241.  
  3242.     # Get name of machine where key is from:
  3243.     $mach= $key->Machine;
  3244.     # Will usually be "" indicating key is on local machine.
  3245.  
  3246.     # Control different options (see main documentation for descriptions):
  3247.     $oldBool= $key->ArrayValues( $newBool );
  3248.     $oldBool= $key->FastDelete( $newBool );
  3249.     $oldBool= $key->FixSzNulls( $newBool );
  3250.     $oldBool= $key->SplitMultis( $newBool );
  3251.     $oldBool= $key->DWordsToHex( $newBool );
  3252.     $oldBool= $key->DualBinVals( $newBool );
  3253.     $oldBool= $key->DualTypes( $newBool );
  3254.     @oldBools= $key->SetOptions( ArrayValues=>1, FastDelete=>1, FixSzNulls=>0,
  3255.       Delimiter=>"/", AllowLoad=>1, AllowSave=>1 );
  3256.     @oldBools= $key->GetOptions( ArrayValues, FastDelete, FixSzNulls );
  3257.  
  3258.     # Add or set a value:
  3259.     $key->SetValue( "ValueName", $valueDataString );
  3260.     $key->SetValue( "ValueName", pack($format,$valueData), "REG_BINARY" );
  3261.  
  3262.     # Add or set a key:
  3263.     $key->CreateKey( "SubKeyName" );
  3264.     $key->CreateKey( "SubKeyName",
  3265.       { Access=>"KEY_ALL_ACCESS", Class=>"ClassName",
  3266.         Delimiter=>"/", Volatile=>1, Backup=>1 } );
  3267.  
  3268.     # Load an off-line Registry hive file into the on-line Registry:
  3269.     $newKey= $Registry->Load( "C:/Path/To/Hive/FileName" );
  3270.     $newKey= $key->Load( "C:/Path/To/Hive/FileName", "NewSubKeyName",
  3271.              { Access=>KEY_READ } );
  3272.     # Unload a Registry hive file loaded via the Load() method:
  3273.     $newKey->UnLoad;
  3274.  
  3275.     # (Dis)Allow yourself to load Registry hive files:
  3276.     $success= $Registry->AllowLoad( $bool );
  3277.  
  3278.     # (Dis)Allow yourself to save a Registry key to a hive file:
  3279.     $success= $Registry->AllowSave( $bool );
  3280.  
  3281.     # Save a Registry key to a new hive file:
  3282.     $key->RegSaveKey( "C:/Path/To/Hive/FileName", [] );
  3283.  
  3284. =head3 Other Useful Methods
  3285.  
  3286. See C<Win32API::Registry> for more information on these methods.
  3287. These methods are provided for coding convenience and are
  3288. identical to the C<Win32API::Registry> functions except that these
  3289. don't take a handle to a Registry key, instead getting the handle
  3290. from the invoking object [C<$key>].
  3291.  
  3292.     $key->RegGetKeySecurity( $iSecInfo, $sSecDesc, $lenSecDesc );
  3293.     $key->RegLoadKey( $sSubKeyName, $sPathToFile );
  3294.     $key->RegNotifyChangeKeyValue(
  3295.       $bWatchSubtree, $iNotifyFilter, $hEvent, $bAsync );
  3296.     $key->RegQueryMultipleValues(
  3297.       $structValueEnts, $cntValueEnts, $Buffer, $lenBuffer );
  3298.     $key->RegReplaceKey( $sSubKeyName, $sPathToNewFile, $sPathToBackupFile );
  3299.     $key->RegRestoreKey( $sPathToFile, $iFlags );
  3300.     $key->RegSetKeySecurity( $iSecInfo, $sSecDesc );
  3301.     $key->RegUnLoadKey( $sSubKeyName );
  3302.  
  3303. =head2 Tied Hashes Summary
  3304.  
  3305. For fast learners, this may be the only section you need to read.
  3306. Always append one delimiter to the end of each Registry key name
  3307. and prepend one delimiter to the front of each Registry value name.
  3308.  
  3309. =head3 Opening keys
  3310.  
  3311.     use Win32::TieRegistry ( Delimiter=>"/", ArrayValues=>1 );
  3312.     $Registry->Delimiter("/");                  # Set delimiter to "/".
  3313.     $swKey= $Registry->{"LMachine/Software/"};
  3314.     $winKey= $swKey->{"Microsoft/Windows/CurrentVersion/"};
  3315.     $userKey= $Registry->
  3316.       {"CUser/Software/Microsoft/Windows/CurrentVersion/"};
  3317.     $remoteKey= $Registry->{"//HostName/LMachine/"};
  3318.  
  3319. =head3 Reading values
  3320.  
  3321.     $progDir= $winKey->{"/ProgramFilesDir"};    # "C:\\Program Files"
  3322.     $tip21= $winKey->{"Explorer/Tips//21"};     # Text of tip #21.
  3323.  
  3324.     $winKey->ArrayValues(1);
  3325.     ( $devPath, $type )= $winKey->{"/DevicePath"};
  3326.     # $devPath eq "%SystemRoot%\\inf"
  3327.     # $type eq "REG_EXPAND_SZ"  [if you have SetDualVar.pm installed]
  3328.     # $type == REG_EXPAND_SZ  [if you did "use Win32API::Registry qw(REG_)"]
  3329.  
  3330. =head3 Setting values
  3331.  
  3332.     $winKey->{"Setup//SourcePath"}= "\\\\SwServer\\SwShare\\Windows";
  3333.     # Simple.  Assumes data type of REG_SZ.
  3334.  
  3335.     $winKey->{"Setup//Installation Sources"}=
  3336.       [ "D:\x00\\\\SwServer\\SwShare\\Windows\0\0", "REG_MULTI_SZ" ];
  3337.     # "\x00" and "\0" used to mark ends of each string and end of list.
  3338.  
  3339.     $winKey->{"Setup//Installation Sources"}=
  3340.       [ ["D:","\\\\SwServer\\SwShare\\Windows"], "REG_MULTI_SZ" ];
  3341.     # Alternate method that is easier to read.
  3342.  
  3343.     $userKey->{"Explorer/Tips//DisplayInitialTipWindow"}=
  3344.       [ pack("L",0), "REG_DWORD" ];
  3345.     $userKey->{"Explorer/Tips//Next"}= [ pack("S",3), "REG_BINARY" ];
  3346.     $userKey->{"Explorer/Tips//Show"}= [ pack("L",0), "REG_BINARY" ];
  3347.  
  3348. =head3 Adding keys
  3349.  
  3350.     $swKey->{"FooCorp/"}= {
  3351.         "FooWriter/" => {
  3352.             "/Version" => "4.032",
  3353.             "Startup/" => {
  3354.                 "/Title" => "Foo Writer Deluxe ][",
  3355.                 "/WindowSize" => [ pack("LL",$wid,$ht), REG_BINARY ],
  3356.                 "/TaskBarIcon" => [ "0x0001", REG_DWORD ],
  3357.             },
  3358.             "Compatibility/" => {
  3359.                 "/AutoConvert" => "Always",
  3360.                 "/Default Palette" => "Windows Colors",
  3361.             },
  3362.         },
  3363.         "/License", => "0123-9C8EF1-09-FC",
  3364.     };
  3365.  
  3366. =head3 Listing all subkeys and values
  3367.  
  3368.     @members= keys( %{$swKey} );
  3369.     @subKeys= grep(  m#^/#,  keys( %{$swKey->{"Classes/batfile/"}} )  );
  3370.     # @subKeys= ( "/", "/EditFlags" );
  3371.     @valueNames= grep(  ! m#^/#,  keys( %{$swKey->{"Classes/batfile/"}} )  );
  3372.     # @valueNames= ( "DefaultIcon/", "shell/", "shellex/" );
  3373.  
  3374. =head3 Deleting values or keys with no subkeys
  3375.  
  3376.     $oldValue= delete $userKey->{"Explorer/Tips//Next"};
  3377.  
  3378.     $oldValues= delete $userKey->{"Explorer/Tips/"};
  3379.     # $oldValues will be reference to hash containing deleted keys values.
  3380.  
  3381. =head3 Closing keys
  3382.  
  3383.     undef $swKey;               # Explicit way to close a key.
  3384.     $winKey= "Anything else";   # Implicitly closes a key.
  3385.     exit 0;                     # Implicitly closes all keys.
  3386.  
  3387. =head2 Tie::Registry
  3388.  
  3389. This module was originally called C<Tie::Registry>.  Changing code
  3390. that used C<Tie::Registry> over to C<Win32::TieRegistry> is trivial
  3391. as the module name should only be mentioned once, in the C<use>
  3392. line.  However, finding all of the places that used C<Tie::Registry>
  3393. may not be completely trivial so we have included F<Tie/Registry.pm>
  3394. which you can install to provide backward compatibility.
  3395.  
  3396. =head1 AUTHOR
  3397.  
  3398. Tye McQueen, tye@metronet.com, see http://www.metronet.com/~tye/.
  3399.  
  3400. =head1 SEE ALSO
  3401.  
  3402. C<Win32API::Registry> - Provides access to Reg*(), HKEY_*,
  3403. KEY_*, REG_* [required].
  3404.  
  3405. C<Win32::WinError> - Defines ERROR_* values [optional].
  3406.  
  3407. C<SetDualVar> - For returning REG_* values as combined
  3408. string/integer [optional].
  3409.  
  3410. =head1 BUGS
  3411.  
  3412. Because I<Win32::TieRegistry> requires C<Win32API::Registry>
  3413. which uses the standard Perl tools for building extensions,
  3414. L<MakeMaker>, and these are not supported with the ActiveWare
  3415. versions of Perl, I<Win32::TieRegistry> cannot be used with the
  3416. ActiveWare versions of Perl.  Sorry.  The ActiveWare version and
  3417. standard version of Perl are merging so you may want to switch to
  3418. the standard version of Perl soon.
  3419.  
  3420. Because Perl hashes are case sensitive, certain lookups are also
  3421. case sensistive.  In particular, the root keys ("Classes", "CUser",
  3422. "LMachine", "Users", "PerfData", "CConfig", "DynData", and HKEY_*)
  3423. must always be entered without changing between upper and lower
  3424. case letters.  Also, the special rule for matching subkey names
  3425. that contain the user-selected delimiter only works if case is
  3426. matched.  All other key name and value name lookups should be case
  3427. insensitive because the underlying Reg*() calls ignore case.
  3428.  
  3429. Perl5.004_02 has bugs that make Win32::TieRegistry fail in strange
  3430. and subtle ways.
  3431.  
  3432. Information about each key is cached when using a tied hash.  A
  3433. future release should use C<RegNotifyChangeKeyValue()> to prevent
  3434. this cache from becoming out-of-date.
  3435.  
  3436. There is no test suite.
  3437.  
  3438. =cut
  3439.  
  3440. # Autoload not currently supported by Perl under Windows.
  3441.